Sample auto start on boot
sample from https://stackoverflow.com/questions/6391902/how-do-i-start-my-app-on-startup
First, you need the permission in your AndroidManifest.xml:
Also, in yourAndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
}
} And now your service should be running when the phone starts up.