【问题标题】:Monitor Notification from other apps监控来自其他应用程序的通知
【发布时间】:2014-08-02 08:33:15
【问题描述】:
【问题讨论】:
标签:
android
notifications
【解决方案1】:
您可以扩展 NotificationListenerService 并覆盖 onNotificationPosted 方法
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.i(TAG, "onNotificationPosted");
Log.i(TAG, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName());
}
您还需要在清单中声明您的服务
<service android:name="yourpackage.yourservice"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>