方法一:

--- 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



更多相关文章

  1. Android 几种加密解密的方法(仅代码)
  2. Android两种轮询的实现方法
  3. Android MonkeyRunner调用方法总结
  4. android home 键的监听方法记录
  5. Android 四种获取屏幕宽度的方法总结
  6. Android 隐藏显示软键盘的终极方法
  7. Android自定义dialog简单实现方法

随机推荐

  1. Android(安卓)Studio升级后工程Build fai
  2. 【Android】ListView内数据的动态追加
  3. 关于 bin/resources.ap_ does not exist
  4. Android4.03中遭遇Installation error: I
  5. Android(安卓)Studio -添加你见过的最牛Lo
  6. Android(安卓)调用已安装市场,去应用市场
  7. Android报错解决 UIL doesn't support sc
  8. android常见错误1
  9. Android中无法访问本地Apache服务器原因
  10. android中实现JavaScript与Java之间实现