Method 1:
--- 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); }
Method 2:
Add Android: Priority to androidmanifest. XML to be started by default to increase the priority of broadcast receiving. The higher the value, the higher the priority. In this way, it will first receive the Android. Intent. Category. Home broadcast, as I wrote:
<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
In fact, I want to say that this method is really useful. For example, if there are multiple video players, each time I click a video, I just want to use gallery to play the video, so I am receiving android. intent. action. set Android: priority in intent-filter of view.
For Android: Priority usage, the official instructions are as follows:
-
android:priority
-
The priority that shocould 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:
Use this attribute only if you really need to impose a specificorder in which the broadcasts are stored ed, or want to forceandroid to prefer one activity over others.
The value must be an integer, such"100
". Highernumbers have a higher priority