Programmatically disable / enable notifications

Is there a way to programmatically disable notifications for individual programs? I would like to create a list of all the programs installed on my device, and then check those for which I do not want to receive notifications, and click one button to turn them off / on.

I am trying to create an application that will allow me to turn on some / all notifications by pressing a button and re-enable them through a button click or after a set period of time. Does Android support this? NotificationManager does not have such properties.

+4
source share
3 answers

Unable to disable notifications from other applications. You can control the notifications created by your own application.

Disable app notifications programmatically on Android

Android: is it possible to remove a system notification programmatically?

+2
source

No, you may not be able to on the root device, but this is another story ...

0
source

You can do this using general settings.

You can set the notification settings in the "General Settings" section, and later, if you receive a message, you can decide whether or not to notify.

Below snippet for ReactNative, but you can use it also for native applications

/** * Toggle Notification Setting * * @param showNotifcation */ @ReactMethod public void toggleNotification(boolean showNotifcation) { if (showNotifcation) { Toast.makeText(reactAppContext, "Notification Enabled", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(reactAppContext, "Notification Disabled", Toast.LENGTH_SHORT).show(); } getPrefernceHelperInstace().setBoolean(reactAppContext, ENABLE_NOTIFICATION, showNotifcation); } 

Later in the messenger class

 public class ReactFireBaseMessagingService extends FirebaseMessagingService { private NotificationUtils notificationUtils; @Override public void onMessageReceived(RemoteMessage remoteMessage) { //Check if Notn are Enabled? if (getPrefernceHelperInstace().getBoolean(getApplicationContext(), ENABLE_NOTIFICATION, true)) { //Show Notification } else { Log.e(TAG, "ReactFireBaseMessagingService: Notifications Are Disabled by User"); } } 

See SNippet Code

https://github.com/hiteshsahu/react-native-fcm-android/blob/master/android/app/src/main/java/com/hitesh_sahu/fcm/service/ReactFireBaseMessagingService.java

enter image description here

0
source

Source: https://habr.com/ru/post/1491558/


All Articles