Reputation: 865
I start a service from app 1. The declaration of service in manifest of this app is as follows:
<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>
I try to bind to this service from a second app. The declaration of service in the manifest of this second app is as follows:
<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>
Following is the code which I use to do bindservice from app 2.
Intent time_intent = new Intent(ITimeServer.class.getName());
mContext.bindService(time_intent, time_connection, Context.BIND_AUTO_CREATE);
I get the following exception when I try to bind to the service which was already started from app 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
When I delete app 1, I get to bind to service without any issues.
Can someone please let me know the cause and solution for this issue?
Any help is much appreciated.
Upvotes: 0
Views: 992
Reputation: 1667
Use this code:
Intent intent = new Intent();
intent.setAction("com.action");
intent.setPackage("com.package.to.service");
Upvotes: 0
Reputation: 1327
You have missed writing android:process=":remote" in your manifest.. Your declaration should be
<service android:name="jp.co.xyz.bluetooth.profile.TIPServer" android:process=":remote">
The android:process=":remote" attribute tells Android to run our service in a separate process from the rest of the application
Upvotes: 2