多个launcher时开机只启动默认的

来源:互联网 发布:艺恩票房数据 编辑:程序博客网 时间:2024/04/28 12:13

方法一:

--- a/services/java/com/android/server/pm/PackageManagerService.java+++ b/services/java/com/android/server/pm/PackageManagerService.java@@ -2839,6 +2839,13 @@ public class PackageManagerService extends IPackageManager.Stub {             int flags, int userId) {         if (!sUserManager.exists(userId)) return null;         List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);+        Slog.e("sclu", "size = " + query.size());+    for(int i = 0; i < query.size(); i++){+        Slog.e("sclu", query.get(i).activityInfo.packageName);+        if(query.get(i).activityInfo.packageName.equals("com.android.launcher")){+            query.remove(i);+        }+    }         return chooseBestActivity(intent, resolvedType, flags, query, userId);     } @@ -2992,6 +2999,7 @@ public class PackageManagerService extends IPackageManager.Stub {                 ri.activityInfo = ai;                 list.add(ri);             }+             return list;         } @@ -3020,6 +3028,13 @@ public class PackageManagerService extends IPackageManager.Stub {         List<ResolveInfo> results = queryIntentActivities(intent, resolvedType, flags                 | PackageManager.GET_RESOLVED_FILTER, userId); +        Slog.e("sclu ", "size = " + results.size());+    for(int i = 0; i < results.size(); i++){+        Slog.e("sclu", results.get(i).activityInfo.packageName);+        if(results.get(i).activityInfo.packageName.equals("com.myapphone.logicom.tabkids")){+            results.remove(i);+        }+    }         if (DEBUG_INTENT_MATCHING) {             Log.v(TAG, "Query " + intent + ": " + results);         }



方法二:

在想要默认启动的AndroidManifest.xml 中加入android:priority来提高接收广播的优先级,数值越高,优先级就越高。这样它会首先接收到android.intent.category.HOME广播,如我自己写的:

        <activity android:name=".MainActivity"            android:excludeFromRecents="true">            <intent-filter android:priority="3">                                                                                                                               <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.HOME" />                <category android:name="android.intent.category.LAUNCHER" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        </activity>        <activity

其实我想说,这个方法真的很有用,比如有多个视频播放器,每次点击视频时候我只想用gallery来播放,那么在接收android.intent.action.VIEW的intent-filter中设置android:priority即可

关于android:priority的用法,官方说明如下:

android:priority
The priority that should be given to the parent component withregard to handling intents of the type described by the filter.This attribute has meaning for both activities and broadcastreceivers:
  • It provides information about how able an activity is torespond to an intent that matches the filter, relative to otheractivities that could also respond to the intent. When an intentcould be handled by multiple activities with different priorities,Android will consider only those with higher priority values aspotential targets for the intent.
  • It controls the order in which broadcast receivers are executedto receive broadcast messages. Those with higher priority valuesare called before those with lower values. (The order applies onlyto synchronous messages; it's ignored for asynchronousmessages.)

Use this attribute only if you really need to impose a specificorder in which the broadcasts are received, or want to forceAndroid to prefer one activity over others.

The value must be an integer, such as "100". Highernumbers have a higher priority



原创粉丝点击