註冊廣播
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.
PACKAGE_REPLACED")){
startApp(context);
}else if(intent.getAction().equals("android.intent.action.PACKAGE_ADDED")){
startApp(context);
}
}
private void startApp(Context context) {
context.startActivity(new Intent(context.getPackageManager().getLaunchIntentForPackage(AppConfig.APP_PACKAGE_PATH)));
}
配置
<receiver android:name=".receiver.DeviceReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN"></action>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_REPLACED"></action>
<action android:name="android.intent.action.PACKAGE_REMOVED"></action>
<data android:scheme="package"></data>
<category android:name="android.intent.category.HOME"></category>
</intent-filter>
</receiver>