Can't cancel Notification using NotificationListenerService

前端 未结 2 1889
天涯浪人
天涯浪人 2020-12-21 09:13

This is my service:

public class Listener extends NotificationListenerService {
    Context context;

    @Override

    public void onCreate() {
        su         


        
相关标签:
2条回答
  • 2020-12-21 09:44

    Make sure the 'Notification Access' is active (checked) for the app implementing your NotificationListenerService.

    It can be verified in 'Settings' menu. It is at either of the addresses depending upon the Android version. For Android 5.0, it should be at: Settings -> Sound & notification -> Notification Access

    Or else, you may find at: Settings -> Security -> Notification Access

    Try enabling it for your app and then try to clear the notifications.

    0 讨论(0)
  • 2020-12-21 09:54

    For how to let user enable their Notification Access,

    You can show a Popup ("Please enable Notification Access"), and when user clicks "OK", it will redirect user to the settings page, to enable the Notification Access settings.

    private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS";
    
    private void openNotificationAccess() {
        startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));
    }
    
    0 讨论(0)
提交回复
热议问题