How to get user data from android fire database notifications?

I am trying to implement firewall notifications. But it's hard for me to find any documentation on how to extract user data from firebase notifications.

Firebase console

But in the code, how to get a user key.

enter image description here

I am using FirebaseMessagingService.onMessageReceived to receive message data.

 @Override public void onMessageReceived(RemoteMessage remoteMessage) { // TODO(developer): Handle FCM messages here. // If the application is in the foreground handle both data and notification messages here. // 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. Log.d(TAG, "From: " + remoteMessage.getFrom()); Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); } 
+5
source share
2 answers

You can check your user data using:

 for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); Log.d(TAG, "key, " + key + " value " + value); } 

To get a specific key:

 String value = remoteMessage.getData().get("<YOUR_KEY>"); 
+20
source

Let A be your key, then you can easily analyze this value using the following code.

 JSONObject json = new JSONObject(remoteMessage.getData()); Iterator itr = json.keys(); while (itr.hasNext()) { String key = (String) itr.next(); if (key.equals("A")) { flag = json.getString(key); } Log.d(TAG, "..." + key + " => " + json.getString(key)); } 
+5
source

All Articles