Android上的一些应用都有拦截短信广播的功能,360,各种手机卫士,还有一些通讯录。最恼人的就是通讯录这些,有的甚至是拦截短信,扔掉广播,由它帮你入库。
经过反编译,有点眉目。360,金山手机卫士的manifest里面根本就没有注册短息的Receiver,所以他们只可能是动态注册短信广播接收器。
还有这个东西:
[html] view plaincopy
优先级他们都会设置成这个很长的int,其实这个数是最大int型整数。
我在网上看到过一些,说是动态注册的广播接收器优先级高于静态注册,此时便很清楚了。
我们可以测试一下,写一个开机启动的Receiver:
[html] view plaincopy
[html] view plaincopy
在onreceiver里面启动一个service: [java] view plaincopy @Override public void onReceive(Context context, Intent intent) { Intent intent2 = new Intent(); intent2.setClass(context, SmsService.class); context.startService(intent2); } 在这个service里面动态注册短息的广播接收器: [java] view plaincopy 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(); } }
}
运行程序,然后重启,给模拟器发送短信,结果是测试程序给拦掉了,金山,360没有反映。说下这个有序广播的优先级问题。以下有部分我没有测试过,也是四处看的,如果有错,请您纠正。
动态注册优先级别高于静态注册
在动态注册中
最早动态注册优先级别最高在静态注册中
最早安装的程序,静态注册优先级别最高(安装APK会解析manifest.xml,把其加入队列)
这里安装的应用不包括rom里面的应用。
然后才是adb push到其他目录的应用。
可能的原因是手机查询应用的时候会先去特定目录解析应用,所以广播注册会出现这种差别。adb push 到system/app下会比安装的优先级高吗?这有待验证,我还没测试过。
然后都是安装的应用中,首先安装的优先等级最高。
个人认为这种有序广播存在很大的不足,导致大量第三方应用程序滥用方法去抢夺广播优先级。