Start downloading your phone in Android

I want to start my application automatically when the phone boots. I declared BroadcastReceiver in the manifest file.

<receiver android:name=".Autostart"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> 

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

I made a Java file for the recipient.

Autostart.java

 public class Autostart extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { Intent pushIntent = new Intent(context, MushTouchActivity.class); pushIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(pushIntent); } } 

}

But the application does not start when you turn on the phone. Can someone tell me what I am missing here?

+2
source share
2 answers

try the if statement as follows:

  if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ Intent i = new Intent(context, MushTouchActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } 
+4
source

If you are on Android 3.1 or later:

Make sure that you start the application at least once manually (for example, by opening it from the application drawer). Otherwise, your application will be marked as stopped by the system:

Applications are stopped when they are first installed but not yet launched

Stopped applications do not receive broadcasts, including BOOT_COMPLETED .

See Android 3.1. Platform - Launch controls for stopped applications for more information.

+2
source

Source: https://habr.com/ru/post/949297/


All Articles