简体   繁体   中英

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 ?

Have you tried 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.

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM