I need to start a push notification service when the phone boots.
I have followed various guides and various answers also to questions asked on this site but without success. The app works (no errors in the log) but at boot it does not start the service.
This is my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
This is my class
public class AutoStarter extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.d("test", "in boot ok ");
Intent ii = new Intent(context.getApplicationContext(), MainActivity.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
ii.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(ii);
Log.d("test", " after boot ok ");
}
In log, after reboot, i see ACTION_BOOT_COMPLETED is OK.