9

i created a library with a service in that i want to be able to bind to in more than one apk.

This is in my libraries manifest

<service class=".service.MyService" android:permission="com.wissen.permission.MY_SERVICE_PERMISSION">
<intent-filter>
<action android:value="com.wissen.testApp.service.MY_SERVICE" />
</intent-filter>
</service>

and this is in my apk manifest

<uses-permission android:name="com.wissen.permission.MY_SERVICE_PERMISSION"></uses-permission>

and i of course added the lib to the apk. i keep on getting service not found (warning). What am i doing wrong.

i bind it this way

bindService(new Intent("com.wissen.testApp.service.MY_SERVICE"), conn, Context.BIND_AUTO_CREATE);

Solution:
I created aidl for these and its working fine now.

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
Pintac
  • 1,565
  • 3
  • 21
  • 38

3 Answers3

27

The service needs to be specified in the Manifest for your application, not the library.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • This should work fine. I think eventually `` elements and the like defined in a library will be automatically included in host project, but I don't think that's there yet. Just copy the `` element from the library's manifest and put it in the host application. – CommonsWare Mar 22 '11 at 17:02
  • I add it but the problem with that i have to define in both apk's( manifest) and then when i bind it in one and try binding it in another it creates a new instance it does not use the same instance of the service or it looked like it. i put a log in the create and it called it twice also i tryed calling a set i have in my binding object and it does not reflect if call the get from the second apk so it must be creating two instances. – Pintac Mar 22 '11 at 22:03
  • 3
    isn't there some more elegant solution than asking developers to add service in their app manifest? – Ewoks Jan 14 '14 at 08:57
  • 7
    Manifest merging will now put a service declared in the library project into the application's manifest file. – James Goodwin Nov 01 '16 at 09:55
1

Your service must be a remote service. You should create an *.aidl (interface to your service) and start it in it's own process. You can read about it here: Android Interface Definition Language (AIDL)

Marcel Gosselin
  • 4,610
  • 2
  • 31
  • 54
UAS
  • 405
  • 2
  • 4
  • 9
  • 7
    No, it does not need to be a remote service to be used from an Android library project. That would be needed only if the service were in a totally separate application. – CommonsWare Mar 22 '11 at 17:00
  • @CommonsWare What would be another method of declaring a service in a library? – Bryan Nov 30 '17 at 19:48
  • @Bryan: I do not understand your question, sorry. You might want to ask a fresh Stack Overflow question where you can explain in greater detail your concerns. – CommonsWare Nov 30 '17 at 19:51
1

I created aidl for these and its working fine now.

Pintac
  • 1,565
  • 3
  • 21
  • 38