android開機自啟動app示例分享
阿新 • • 發佈:2019-02-09
/*開機自動啟動APP*/
public class BootReceiver extends BroadcastReceiver {@Override
public void onReceive(Context context, Intent intent) {
Log.d("XRGPS", "BootReceiver.onReceive: " + intent.getAction());
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent mBootIntent = new Intent(context, MainActivity.class);
mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mBootIntent);
} else {
Log.w("XRGPS", "BootReceiver: unsupported action");
}
}
}
public class BootReceiver extends BroadcastReceiver {@Override
public void onReceive(Context context, Intent intent) {
Log.d("XRGPS", "BootReceiver.onReceive: " + intent.getAction());
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent mBootIntent = new Intent(context, MainActivity.class);
mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mBootIntent);
} else {
Log.w("XRGPS", "BootReceiver: unsupported action");
}
}
}