<uses-permission android:name="android.permission.INTERNET"/>
<service
android:name=".NotificationMonitor"
android:label="nb"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationMonitor extends NotificationListenerService {
@SuppressLint("NewApi")
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
//有新通知添加的时候调用
Log.e("onNotificationPosted","posted");
Log.i("xiaolong", "open" + "-----" + sbn.getPackageName());
Log.i("xiaolong", "open" + "------" + sbn.getNotification().tickerText);
Log.i("xiaolong", "open" + "-----" + sbn.getNotification().extras.get("android.title"));
Log.i("xiaolong", "open" + "-----" + sbn.getNotification().extras.get("android.text"));
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
//通知被移除的时候调用
Log.e("onNotificationRemoved","posted");
Log.i("xiaolong", "remove" + "-----" + sbn.getPackageName());
}
private boolean isNotificationServiceEnable() {
return NotificationManagerCompat.getEnabledListenerPackages(this).contains(getPackageName()); }
}
1676

被折叠的 条评论
为什么被折叠?



