Trying to start a service on boot on Android
- by Alex
I've been trying to start a service when a device boots up on android, but I cannot get it to work.
I've looked a number of links online but none of the code is working. Am I forgetting something? This is my code.
Manifest
<receiver android:name=".StartServiceAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service android:enabled="true" android:name="com.test.RunService"/>
Receiver OnReceive
public void onReceive(Context context, Intent intent)
{
if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
{
Intent serviceLauncher = new Intent(context, RunService.class);
context.startService(serviceLauncher);
Log.v("TEST", "Service loaded at start");
}
}
Thanks,