0

If I have a preference of whether the user wants to enable notification or not. Which event should I send so that I can exclude this user when sending the notification?

adjuremods
  • 2,938
  • 2
  • 12
  • 17
weijia_yu
  • 965
  • 4
  • 14
  • 31

1 Answers1

0

On the onMessageReceived method, try to validase if in SharedPReferences has a notifications (bool) = true.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...



// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be
Log.d(TAG, "From: " + remoteMessage.getFrom());

// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
    Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}

// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
    Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}

// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
 }

From: https://firebase.google.com/docs/notifications/android/console-audience

Cristian Cardoso
  • 665
  • 6
  • 11
  • it seems it is for foreground usage, if the app is in background it will not work. I decided to use user segment instead, use setUserProperty("ifNotification", "false"); – weijia_yu Nov 11 '16 at 07:00