Android系统通知监听方案
2017-09-10 17:29
225 查看
1.继承NotificationListenerService类,复写两个方法
public class NLService extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { } @Override public void onNotificationRemoved(StatusBarNotification sbn) { } }
2.在AndroidManifest.xml中注册Service并声明相关权限;
<service android:name=".NLService" android:label="@string/service_name" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service>
3.配置系统级权限
1 、通过shareduserid来获取系统权限
(1) 在AndroidManifest.xml中添加android:sharedUserId="android.uid.system"
(2) 在Android.mk文件里面添加LOCAL_CERTIFICATE := platform(使用系统签名)
(3) 在源码下面进行mm编译,这样生成的apk能够获取system权限,可以在任意system权限目录下面进行目录或者文件的创建,以及访问其他apk
2、使用手机的platform平台签名后,能够获取到系统权限。
1>在AndroidManifest.xml设置android:sharedUserId="android.uid.system"。
2>编译通过后,从eclipse导出未签名的SetGPS.apk。
3>使用\out\host\Linux-x86\framework\signapk.jar +\build\target\product\security\platform.pk8 +platform.x509.pem
把这三个文件放到同一个文件中
4>执行“Java -jar signap
4000
k.jar platform.x509.pem platform.pk8 SetGPS.apk SetGPSSigned.apk”做平台签名得到SetGPSSigned.apk。
这样不用root push到system/app/ ,直接 install 安装后即可使用。
5>编译通过后,从eclipse导出未签名的SetGPS.apk。
4.代码增加授权
Settings.Secure.putString(this.getContentResolver(), "enabled_notification_listeners", new ComponentName(getApplicationContext(), com.example.notification.NotificationMonitorService.class).flattenToString());
相关文章推荐
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- android之Notification监听系统清除通知栏
- Android平台监听系统截屏方案预研及相关知识点
- 立即获得下载任务完成的消息通知。Android DownloadManager通过注册一个广播监听系统的广播事件完成此操作,在创建广播时候,需要指明过滤器为:DownloadManager.ACTIO
- android 监听软键盘弹出和隐藏和4.4系统沉浸式通知栏冲突解决
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- Android Notification之监听系统清除通知栏方法
- 主动通知Android系统刷新文件,并对刷新进度做监听
- Android使用ContentObserver监听数据库变化,截取系统通知用户接收到短信
- Android 自定义Notification通知样式并设置按钮监听.
- android监听系统联系人修改
- 利用广播接收者监听Android系统网络变化
- 我的Android进阶之旅------>Android系统设置默认来电铃声、闹钟铃声、通知铃声
- Android应用获取通知栏权限是否开启--以及跳转到系统设置界面--解决方案
- android 一些系统自带的通知,服务,活动和数据
- 浅析Android 4.0的通知系统(附Android 4.0设计指南全文翻译)
- Android利用系统广播---监听应用程序安装和卸载
- Android 自定义锁屏 监听系统消息推送
- 【笔记】Android NotificationListenerService监听短信、来电、微信、QQ等通知消息
- 添加android系统通知