Not able to send push notifications to specific users using device tokens.
How can I send push notifications using only device-tokens to specific user obtained from FirebaseMessaging in android. I actually want to notify users whether their tickets are verified or rejected , here is my code please and help me out please,
private void sendNotificationRequest(String title, String message,String deviceToken) throws JSONException {
JSONObject mainObject = new JSONObject();
mainObject.put("to","/"+deviceToken);
JSONObject notificationDataObject = new JSONObject();
notificationDataObject.put("title",title);
notificationDataObject.put("body",message);
mainObject.put("notification",notificationDataObject);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, POST_BASE_URL,
mainObject,
response -> {
}, error -> {
}
)
{
@Override
public Map<String, String> getHeaders() {
Map<String, String> header = new HashMap<>();
header.put("content-type","application/json");
header.put("authorization","key="+SERVER_KEY);
return header;
}
};
requestQueue.add(jsonObjectRequest);
}