My goal is to make 3 apks (for a very specific solution, not for normal consumption):
- First contains the service, which starts at boot
- A client that uses this service
- Another client that uses this service
According to this site:
http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/
I can to start a service just by knowing its name. However, this does not work:
// works
context.startService(new Intent(context, MyServiceMessenger.class));
// does not work
Intent serviceIntent = new Intent();
serviceIntent.setAction(MyService.SERVICE_CLASS_NAME);
context.startService(serviceIntent);
Needles to say the MyService.SERVICE_CLASS_NAME== mypackage.MyServiceMessenger.
My problem is on binding – where I need to bind to a service outside of my class.
// does not work
Intent intent = new Intent(context, MyService.SERVICE_CLASS_NAME);
// works
Intent intent = new Intent(context, MyServiceMessenger.class);
intent.putExtra("MESSENGER", messenger);
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
When binding to the service by name, my serviceConnection is not been used at all, and I cannot send information to the service.
What am I missing?
Edit1:
I was missing an export in the manifest. You need to “export” it, and give it a name. I also gave permission to it. I am using the same string in my intent as the one in @@ .
<permission android:name="MyPermission"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="dangerous" />
<uses-permission android:name="MyPermission" />
<application ... >
<service
android:name="service.MyServiceMessenger"
android:exported="true"
android:permission="MyPermission" >
<intent-filter>
<action android:name="**platinum8.service.P2PServiceMessenger**"></action>
</intent-filter>
</service>
</application>
EDIT 2:
I added an intent-filter with the same of the service name, and now my code seems to work.
Possibly you are missing an
<intent-filter>on your<service>element, where you declare the<action>you are trying to have the service respond to, such as: