You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
Java
31 lines
1.0 KiB
Java
2 years ago
|
package com.xypower.mpapp;
|
||
|
|
||
|
import android.content.BroadcastReceiver;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
|
||
|
public class BootBroadcastReceiver extends BroadcastReceiver {
|
||
|
private static final String ACTION = "android.intent.action.BOOT_COMPLETED";
|
||
|
|
||
|
@Override
|
||
|
public void onReceive(Context context, Intent intent) {
|
||
|
// Log.e("接收广播", "onReceive: ");
|
||
|
// Log.e("接收广播", "onReceive: " + intent.getAction());
|
||
|
//开机启动
|
||
|
if (ACTION.equals(intent.getAction())) {
|
||
|
// Log.e("接收广播", "onReceive: 启动了。。。");
|
||
|
|
||
|
Intent mainIntent = new Intent(context, MainActivity.class);
|
||
|
mainIntent.putExtra("reboot", 1);
|
||
|
/**
|
||
|
* Intent.FLAG_ACTIVITY_NEW_TASK
|
||
|
* Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||
|
*/
|
||
|
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||
|
context.startActivity(mainIntent);
|
||
|
|
||
|
// context.startService(mainIntent);
|
||
|
}
|
||
|
}
|
||
|
}
|