[英]Perform an action when a notification is canceled by the system or anything else but the user
Is there a way to perform an action when a notification is canceled by the system (by shutting down or restarting) or any other stuff but the user ? 当系统(通过关闭或重新启动)或除用户以外的其他任何东西取消通知时,是否有办法执行操作?
If so, how ? 如果是这样,怎么办? Or how can I implement onNotificationRemoved ?
或如何实现onNotificationRemoved ?
Have you tried NotificationListenerService ? 您是否尝试过NotificationListenerService ?
This is a service that receives calls from the system when new notifications are posted or removed, or their ranking changed. 当发布或删除新通知或更改其排名时,该服务会接收来自系统的呼叫。
To extend this class, you must declare the service in your manifest file with the BIND_NOTIFICATION_LISTENER_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action. 要扩展此类,您必须使用BIND_NOTIFICATION_LISTENER_SERVICE权限在清单文件中声明服务,并在SERVICE_INTERFACE操作中包含意图过滤器。
<service android:name=".NotificationListener"
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>
Now, in your Notification Listner class, implement onNotificationRemoved
现在,在您的Notification Listner类中,实现
onNotificationRemoved
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.