Android BroadcastReceiver, auto run service after reboot of device

Use this code on your Broadcast Receiver class:

if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
   Intent service = new Intent(context, MsgPushService.class);  
    context.startService(service);  
  }

Though all the above answers were correct, however from Android Oreo they put some limitation on Background Services.

Check Background Execution Limits to know more about background limits in Android O.

You can't start a Service directly from BroadCastReceiver when the application is in the background.

However, you can start a foreground service from the receiver by calling startForegroundService() or use JobIntentService as there is no such limitation with JobIntentService.


You forgot about the permissions

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />