1、android service通知activity更新
方式有
1. service 经过广播的形式发送broadcast,向这个activity的内部类发广播的消息来更新界面
2. service直接向activity发intent,把activity的launchMode设置为singleInstancehtml
2、安全性
这边关注第1种方式的广播和接收intent安全,若是不对广播的发送和接收进行判断,会有很大的安全隐患
在个人场景中,是动态注册broadcast,考虑安全以下:android
A、针对sendBroadcast
1.一般采用的安全方式有setPackage设置包名
intent.setAction("com.example.tianqitong.recv");
intent.setPackage("com.example.tianqitong");
sendBroadcast(intent);安全
2.能够经过使用LocalBroadcastManager,确保了应用程序外部的任何组件都收不到你广播的Intent.net
3.设置权限
sendBroadcast(intent,"broadcast.permission");htm
还要加上android:protectionLevel权限级别blog
<uses-permission android:name="broadcast.permission" /> //声明使用权限
<permission android:name="broadcast.permission" android:protectionLevel="signature" /> //自定义权限接口
B、针对Receive
1.能够经过使用LocalBroadcastManager,使其余应用程序也不能向你的接收器发送广播ip
2.对于动态注册的广播能够经过相似registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)的接口指定发送者必须具有的permission
其中string为指定的permission,必须加android:protectionLevel
譬如:
<permission android:name="broadcast.permission" android:protectionLevel="signature" />string
参考:
http://blog.csdn.net/t12x3456/article/details/9256609
http://blog.csdn.net/hotdogzu/article/details/7940820
http://blog.csdn.net/abc13939746593/article/details/8186916
http://my.eoe.cn/weiblog/archive/4590.html
http://www.sectop.com/?p=187
https://developer.android.com/training/articles/security-tips.html
https://developer.android.com/reference/android/content/BroadcastReceiver.html#Security
http://book.51cto.com/art/201304/389200.htmit