android开机自动启动APP(用BroadcastReceive实现)

1、新建一个继承BroadcastReceive的类

public class StartBoot extends BroadcastReceiver {

    public StartBoot() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        
        Intent intent2 = new Intent(context,MainActivity.class);//
        
        intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//
        context.startActivity(intent2);

    }

}

2.修改AndroidManifest.xml

 
            
                
                
            
        

3、添加权限

 

 

你可能感兴趣的