The project requires an interface to automatically start an app when android is turned on

The project requires an interface to automatically start an app when android is turned on. I found some information on the Internet and confirmed that it is available:

 
The first is to add the following code to the AndroidManifest.xml file of the app you want to start (note that it is added in the application tag):
 
< receiver  android:enabled ="true"  android:name =".BootUpReceiver"    

         android:permission ="android.permission.RECEIVE_BOOT_COMPLETED" >     

         < intent-filter >     

                 < action  android:name ="android.intent.action.BOOT_COMPLETED"  />     

                 < category  android:name ="android.intent.category.DEFAULT"  />     

         </ intent-filter >     

</ receiver >     

< uses-permission  android:name ="android.permission.RECEIVE_BOOT_COMPLETED"  />
Then create a BootUpReceiver class in the project ( MyActivity is the main activity of your own app ):
public  class  BootUpReceiver  extends  BroadcastReceiver{     
         public  void  onReceive(Context context, Intent intent) {     
                Intent i =  new  Intent(context, MyActivity. class );         
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     
                context.startActivity(i);         
        }     
}
After compiling and running, and restarting the system, the app can automatically run after the system is started.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326394100&siteId=291194637