0

According documentaion on Developer's forum, this is how I can bind my service using AIDL:

/* Establish a couple connections with the service, binding by interface names.This allows  other  applications to be installed that replace the remote service by implementingthe same  interface.*/

bindService(new Intent(IRemoteService.class.getName()),mConnection, Context.BIND_AUTO_CREATE);

Now I have application A, which has Service class and AIDL interfaces.

And I have application B through which I wish to access Service class of Application A , using methods exposed ny AIDL in application A.

So I have created exactly same pacakge for AIDLs inside application B and have pasted AIDLs from App A.

But when I'm trying to bind service using above mechanism mentioned in documentation it tells me:

Unable to start service Intent { act com.example.service.MyService } U=0: not found

In App A Service

exported="true".

Now Insted of this approach I added Intent Filter to my service in app A and tried to specify explicit intent using

intent.setClassName(String packageName, String className)

And now it is working!

So is there something I missed out while referring original documentation ? when that approached will be used?

Nayanesh Gupte
  • 2,735
  • 25
  • 37
  • what does IRemoteService.class.getName() return? how did you define your Service in the manifest? – pskink Jul 15 '14 at 05:59
  • 1
    Please refer link at starting of my question which refers to Android documenataion. http://developer.android.com/guide/components/aidl.html#Calling – Nayanesh Gupte Jul 15 '14 at 06:09
  • you didn't answer, how did you declare your Service in the manifest? – pskink Jul 15 '14 at 06:27
  • 1
  • so add an intent-filter with a unique action e. g. "com.example.service.MyService.ACTION_START" and pass that string to Intent constructor – pskink Jul 15 '14 at 06:46
  • I think you did not read my question properly. In that way my code is working, when I added action in manifest and passing to Intent constructor. I'm trying to understand approach mentioned in documentation. Why that didn't work for me? – Nayanesh Gupte Jul 15 '14 at 06:50
  • yes i read it properly i hope, you get an error Unable to start service Intent { act com.example.service.MyService } which means the system cannot start the service since there is no service with intent filter matching the action "com.example.service.MyService", read Intent(String) documentation – pskink Jul 15 '14 at 06:58
  • so does that mean string returned by IRemoteService.class.getName() should be present in manifest under service as action in intent filter? – Nayanesh Gupte Jul 15 '14 at 07:02
  • dont use actions like IRemoteService.class.getName(), see Intent.ACTION_* constants and follow the naming rules, e. g. android.intent.action.PICK – pskink Jul 15 '14 at 07:09
  • okay. My concern was to understand the approach mentioned in sample mentioned in documentation, under assumption that standard practices are being followed there. Also even if I mention appropriate action, I get a warning saying implicit intents with startService are not safe. However thanks for clearing my doubt! – Nayanesh Gupte Jul 15 '14 at 08:10

1 Answers1

0

After discusing with pskink in above comments I got the answer for this question. The anser lies in my new implementation.

Check the constructor for Intent used in above example in documentation. It tells that IRemoteService.class.getName() passed inside Intent constructor is nothing but an 'Action'. So if I want my code should be able to find the service I wish to bind then the String returned by IRemoteService.class.getName() should be mentioned as an Action inside intent filter for my service.

Two points to be considered here will be:

  1. This won't follow standard naming convention for actions.

  2. Starting service using Implicit intent gives waring as implicit intents with startService are not safe for obvious reason that if the same Action is used by multiple services then it will be a problem.

Nayanesh Gupte
  • 2,735
  • 25
  • 37