Make an email call https://fcm.googleapis.com/fcm/send with the following parameters: -
Headers: -
Content-Type - Applications / JSON
Authorization - key = {your server key}
Body: -
{ "data": { "my_custom_key" : "my_custom_value", "message" : "notification message" }, "registration_ids": ["device_token1,device_token2,.........."] }
EDIT: -
Basically, what you need to do, whenever you need to send a notification, you have to call this POST method on your part, and your application will automatically receive a call in OnMessageReceived. You can treat it like: -
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); // TODO: 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. Log.d(TAG, "From: " + remoteMessage.getFrom()); Map<String, String> data=remoteMessage.getData(); Log.d(TAG, "From: " + data.toString()); String value=data.get("my_custom_key"); Log.d(TAG, "From: " + value); String msg=data.get("message"); Log.d(TAG, "From: " + msg); sendNotification(msg,value,remoteMessage.getSentTime()); }
source share