Android BroadcastReceiver, auto run service after reboot of device
Solution 1:
First do this
1) In your <manifest>
element:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Solution 2:
You forgot about the permissions
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Solution 3:
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.