读取通知栏消息

android4.4以后的版本出现了一个NotificationListenerService(通知监听服务类),因此,我们只需要继承这个服务,然后在

Manifest.xml中注册即可。

package com.example.demo;

import android.app.Notification;
import android.app.Notification.Action;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.widget.Toast;

public class NotificationService extends NotificationListenerService {
	@Override
	public void onNotificationPosted(StatusBarNotification sbn) {
		Notification mNotification = sbn.getNotification();
		if (mNotification != null) {
			String packageName=sbn.getPackageName();//发送通知的包名
			String text=mNotification.tickerText.toString());//通知内容
		}

	}

	@Override
	public void onNotificationRemoved(StatusBarNotification sbn) {
		// TODO 自动生成的方法存根

	}
}

 

<service
            android:name="com.example.demo.NotificationService"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" >
                </action>
            </intent-filter>
        </service>

 

 

 

并且需要调用这个让用户在系统设置中授权应用能够读取通知。

Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);

所以由此可见,经过授权的应用是可以读取通知栏消息的,假如用户随便授权应用,就可能让不良应用读取你手机中的隐私

 

信息,例如各类验证码,聊天工具消息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值