简体   繁体   English

当系统或用户以外的其他任何人取消通知时,执行操作

[英]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.

相关问题 当用户单击通知时,Titanium Android Notification执行操作 - Titanium Android Notification perform action when user clicks notification 上次包含通知被取消时,组摘要通知未取消 - Group summary notification not canceled when last containing notification is canceled Android通知完成后如何执行操作? - How do I perform an action when an Android Notification is complete? 为什么取消通知时不调用deleteIntent(PendingIntent)? - Why is deleteIntent(PendingIntent) not called when notification is canceled? 单击“ addAction”图标时,Android通知未取消 - Android notification not canceled when clicking “addAction” icon 当用户单击通知时,通知的意图/操作未传递 - Intent/action from notification not passed on when user clicks on notification 系统日期更改时如何执行某些操作? - How to perform some action when the system date changes? 通知操作需要单击两次以执行操作 - Notification action need to click twice to perform action 单击 FCM 通知时取消 Flutter 通知挂起意图 - Flutter Notification pending intent canceled when clicked on FCM notification 按下布局按钮时如何取消自定义布局通知? - how to make a custom layout notification canceled when a layout button is pressed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM