package com.example.x_yp.system_camera; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; /** * 实现开机启动 * @author Owner */ public class BootRestartReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
<!-- 开机启动 --> <receiver android:name=".BootRestartReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.HOME"/> </intent-filter> </receiver>
添加用户权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />