經過反編譯,有點眉目。360,金山手機衛士的manifest裏面根本就沒有註冊短息的Receiver,所以他們只可能是動態註冊短信廣播接收器。
還有這個東西:
- <intent-filter android:priority="2147483647">
我在網上看到過一些,說是動態註冊的廣播接收器優先級高於靜態註冊,此時便很清楚了。
我們可以測試一下,寫一個開機啓動的Receiver:
- <receiver android:name=".BootReceiver" >
- <intent-filter android:priority="2147483647" >
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
- <pre>
在onreceiver裏面啓動一個service:
- @Override
- public void onReceive(Context context, Intent intent) {
- Intent intent2 = new Intent();
- intent2.setClass(context, SmsService.class);
- context.startService(intent2);
- }
在這個service裏面動態註冊短息的廣播接收器:
- public class SmsService extends Service {
- private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
- @Override
- public IBinder onBind(Intent intent) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void onCreate() {
- IntentFilter filter = new IntentFilter(ACTION);
- filter.setPriority(2147483647);
- MyBrocast myService = new MyBrocast();
- registerReceiver(myService, filter);
- }
- private class MyBrocast extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- System.out.println("receiver message --->>>>");
- abortBroadcast();
- }
- }
- }
說下這個有序廣播的優先級問題。以下有部分我沒有測試過,也是四處看的,如果有錯,請您糾正。
動態註冊優先級別高於靜態註冊
在動態註冊中
最早動態註冊優先級別最高
在靜態註冊中
最早安裝的程序,靜態註冊優先級別最高(安裝APK會解析manifest.xml,把其加入隊列)
這裏安裝的應用不包括rom裏面的應用。
然後纔是adb push到其他目錄的應用。
可能的原因是手機查詢應用的時候會先去特定目錄解析應用,所以廣播註冊會出現這種差別。adb push 到system/app下會比安裝的優先級高嗎?這有待驗證,我還沒測試過。
然後都是安裝的應用中,首先安裝的優先等級最高。
個人認爲這種有序廣播存在很大的不足,導致大量第三方應用程序濫用方法去搶奪廣播優先級。
暫時就這麼多了……