您的当前位置:首页正文

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

2024-11-25 来源:个人技术集锦

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

  <receiver android:name=".StartBoot">
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.HOME"/>
            </intent-filter>
        </receiver>

 

3、添加权限

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

 

转载于:https://www.cnblogs.com/stallran/p/4055103.html

显示全文