OiO.lk Blog java How to remove all notifications using Accessibility?
java

How to remove all notifications using Accessibility?


The task is to remove all notifications that the application creates using Accessibility.

The app runs in the background and generates a notification

Notification notification = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    notification = new Notification.Builder(this, CHANNEL_ID)
            .setContentTitle("Service is running")
            .setContentText("App is performing background tasks")
            .setSmallIcon(R.drawable.ic_service_icon)
            .build();
}

startForeground(1, notification);

`

I’m trying to delete all notifications, the logs show me that the notifications have been deleted, but the notification that the background process creates continues to appear on the phone

`

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    
    AccessibilityNodeInfo nodeInfo = event.getSource();

    if (nodeInfo != null) {
        Log.i(TAG, "onAccessibilityEvent: найдено окно");
        Log.i(TAG,"ForeGround Accessibility");

        
        performActionOnPermissionDialog(nodeInfo);

        
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            Log.i(TAG, "Удаляем уведомления, так как изменилось состояние окна");
            removeNotifications();
        }
    }
}

private void removeNotifications() {
        
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (notificationManager != null) {
           
            notificationManager.cancelAll();
            Log.i(TAG, "Уведомление с ID 1 удалено");
        } else {
            Log.w(TAG, "Не удалось получить NotificationManager");
        }
    }



You need to sign in to view this answers

Exit mobile version