Android短信Receiver优先级

Android上的一些应用都有拦截短信广播的功能,360,各种手机卫士,还有一些通讯录。最恼人的就是通讯录这些,有的甚至是拦截短信,扔掉广播,由它帮你入库。

经过反编译,有点眉目。360,金山手机卫士的manifest里面根本就没有注册短息的Receiver,所以他们只可能是动态注册短信广播接收器。

还有这个东西:

<intent-filter android:priority="2147483647"> 

  优先级他们都会设置成这个很长的int,其实这个数是最大int型整数。

 

 

我在网上看到过一些,说是动态注册的广播接收器优先级高于静态注册,此时便很清楚了。

我们可以测试一下,写一个开机启动的Receiver:

<receiver android:name=".BootReceiver" >  
     <intent-filter android:priority="2147483647" >  
           <action android:name="android.intent.action.BOOT_COMPLETED" />  
     </intent-filter>  
</receiver>  

  

<pre></pre>  
<p></p>  
<p>在onreceiver里面启动一个service:</p>  
<p></p>  
<pre name="code" class="java">  @Override  
    public void onReceive(Context context, Intent intent) {  
        Intent intent2 = new Intent();  
        intent2.setClass(context, SmsService.class);  
        context.startService(intent2);  
    }</pre><br>  
<br>  
<p></p>  
<p>在这个service里面动态注册短息的广播接收器:</p>  
<p></p>  
<pre name="code" class="java">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();  
        }  
  
    }  
  
}  
</pre>运行程序,然后重启,给模拟器发送短信,结果是测试程序给拦掉了,金山,360没有反映。  
<p></p>  
<p><br>  
</p>  
<p>说下这个有序广播的优先级问题。以下有部分我没有测试过,也是四处看的,如果有错,请您纠正。</p>  
<p>动态注册优先级别高于静态注册<br style="word-wrap:break-word">  
<br style="word-wrap:break-word">  
在动态注册中<br style="word-wrap:break-word">  
最早动态注册优先级别最高<br style="word-wrap:break-word">  
<br style="word-wrap:break-word">  
在静态注册中<br style="word-wrap:break-word">  
最早安装的程序,静态注册优先级别最高(安装APK会解析manifest.xml,把其加入队列)<br style="word-wrap:break-word">  
这里安装的应用不包括rom里面的应用。<br style="word-wrap:break-word">  
然后才是adb push到其他目录的应用。<br style="word-wrap:break-word">  
可能的原因是手机查询应用的时候会先去特定目录解析应用,所以广播注册会出现这种差别。adb push 到system/app下会比安装的优先级高吗?这有待验证,我还没测试过。<br style="word-wrap:break-word">  
然后都是安装的应用中,首先安装的优先等级最高。<br>  
</p>  
<p>个人认为这种有序广播存在很大的不足,导致大量第三方应用程序滥用方法去抢夺广播优先级。</p>  
<p>暂时就这么多了……</p>  
<pre></pre>  
<pre></pre>  
<pre></pre>  

  

posted on 2013-06-25 19:20  11133432211  阅读(259)  评论(0)    收藏  举报