It is necessary to get data from remotemessage FCM. When receiving a message, the data is null
I am trying to transfer the data as follows.
public void SendNotifications() {
String numberAuto = MainAdapter.gosNumber.getText().toString();
String token = userFcmToken;
requestQueue = Volley.newRequestQueue(mActivity);
Map<String, String> header = new HashMap<String, String>();
header.put("data", "title");
JSONObject mainObj = new JSONObject();
try {
mainObj.put("to", token);
mainObj.put("data", header);
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, postUrl, mainObj, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println("FCM" + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(mContext, "bad", Toast.LENGTH_SHORT).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
header.put("authorization", "key=" + fcmServerKey);
return header;
}
};
requestQueue.add(request);
} catch (JSONException e) {
e.printStackTrace();
}
}
and get in. I don’t understand how to properly assemble a query with data.
public class FirebaseMessagingServices extends FirebaseMessagingService
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> header = remoteMessage.getData();
JSONObject text;
text = new JSONObject(header);
Log.d(SCREEN_TOGGLE_TAG, "" + text.toString());
}