Android 8.1 预置应用开机自启动
近来接到项目需求,要求将预置应用设置为开机自启动,具体修改参照如下:
方法一:
/packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java
private void loadWorkspace() {if (LauncherAppState.PROFILE_STARTUP) {Trace.beginSection("Loading Workspace");}final Context context = mApp.getContext();final ContentResolver contentResolver = context.getContentResolver();final PackageManagerHelper pmHelper = new PackageManagerHelper(context);final boolean isSafeMode = pmHelper.isSafeMode();final boolean isSdCardReady = Utilities.isBootCompleted();final MultiHashMap<UserHandle, String> pendingPackages = new MultiHashMap<>();boolean clearDb = false;try {ImportDataTask.performImportIfPossible(context);} catch (Exception e) {// Migration failed. Clear workspace.clearDb = true;}
+ Intent startIntent = new Intent();
+ startIntent.setClassName("uAppPackageName","uAppActivityName");
+ context.startActivity(startIntent);if (!clearDb && GridSizeMigrationTask.ENABLED &&!GridSizeMigrationTask.migrateGridIfNeeded(context)) {// Migration failed. Clear workspace.clearDb = true;}
方法二:
/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
mAnrManager.writeEvent(AnrManager.EVENT_BOOT_COMPLETED);
+ Intent startIntent = new Intent();
+ startIntent = mContext.getPackageManager().getLaunchIntentForPackage("uAppPackageName");
+ ifstartIntent != null){
+ mContext.startActivity(startIntent);
+ } else {
+ android.util.Log.i("jc", "getLaunchIntentForPackage failed" );
+ }
重新编译验证,修改生效,预置应用已设置为开机自启动