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
@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) {
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

source share