應用自啓動

註冊廣播

@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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章