|
|
|
package com.xypower.mpapp;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
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: 启动了。。。");
|
|
|
|
|
|
|
|
Log.i("BootBroadcastReceiver", "Start MainActivity");
|
|
|
|
|
|
|
|
/*
|
|
|
|
Intent mainIntent = new Intent(context, MainActivity.class);
|
|
|
|
mainIntent.putExtra("reboot", 1);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
|
|
|
try {
|
|
|
|
pendingIntent.send();
|
|
|
|
} catch (PendingIntent.CanceledException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|