1、`public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
System.out.println("检测到开机启动,去启动服务");
Log.i("343", "检测到开机启动,去启动服务");
Intent newIntent = new Intent(context, StartService.class);
context.startService(newIntent);
//七寸屏开机自启动
Intent startIntent = new Intent(context,SceneQuickActivity.class);
startIntent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
}
}
}
2、开启重启广播接收者 需要权限
android.permission.RECEIVE_BOOT_COMPLETED
3、注册广播
* <receiver android:name=".receiver.BootCompleteReceiver" > <intent-filter>
* <action android:name="android.intent.action.BOOT_COMPLETED" />
* </intent-filter> </receiver>