我从app 1启动了一个服务,这个app的manifest中的service声明如下:
<service android:name="jp.co.xyz.bluetooth.profile.TIPServer"
android:permission="jp.co.abc.android.OMRSSettings.permission.Access" >
<intent-filter>
<action android:name="jp.co.xyz.bluetooth.api.ICommonResultCallback" />
<action android:name="jp.co.xyz.bluetooth.api.ITimeServer" />
</intent-filter>
我尝试从第二个应用程序绑定到此服务。第二个应用程序清单中的服务声明如下:
<service android:name="jp.co.xyz.bluetooth.profile.TIPServer"
android:permission="jp.co.abc.android.OMRSSettings.permission.Access" >
<intent-filter>
<action android:name="jp.co.xyz.bluetooth.api.ICommonResultCallback" />
<action android:name="jp.co.xyz.bluetooth.api.ITimeServer" />
</intent-filter>
以下是我用来从应用程序 2 执行绑定服务的代码。
Intent time_intent = new Intent(ITimeServer.class.getName());
mContext.bindService(time_intent, time_connection, Context.BIND_AUTO_CREATE);
当我尝试绑定到已从应用程序 1 启动的服务时,出现以下异常。
01-02 00:06:54.531: INFO/PowerManagerService(425): Start Light.setBrightness(), [20], [3]
01-02 00:06:56.473: INFO/PowerManagerService(425): Start Light.setBrightness(), [130], [3]
01-02 00:06:58.055: WARN/dalvikvm(4956): threadid=1: thread exiting with uncaught exception (group=0x40b70390)
01-02 00:06:58.055: WARN/ActivityManager(425): Permission Denial: Accessing service ComponentInfo{jp.co.abc.android.omrsettings/jp.co.xyz.bluetooth.profile.TIPServer} from pid=4956, uid=10158 requires jp.co.abc.android.OMRSettings.permission.Access
01-02 00:06:58.065: ERROR/AndroidRuntime(4956): FATAL EXCEPTION: main
java.lang.SecurityException: Not allowed to bind to service Intent { act=jp.co.xyz.bluetooth.api.ITimeServer }
at android.app.ContextImpl.bindService(ContextImpl.java:1187)
at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
at jp.co.abc.middleware.tip.LeTimeServerProfile.startTimeServer(LeTimeServerProfile.java:45)
at jp.co.abc.tip.TimeActivity.onClick(TimeActivity.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14133)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
01-02 00:06:58.095: WARN/ActivityManager(425): Force finishing activity jp.co.abc.tip/.TimeActivity
当我删除应用程序 1 时,我可以毫无问题地绑定到服务。
有人可以让我知道这个问题的原因和解决方案吗?
任何帮助深表感谢。