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.
TermApp/app/src/main/java/com/xypower/mpapp/BootBroadcastReceiver.java

45 lines
1.6 KiB
Java

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