phpdroid
phpdroid

Reputation: 1663

Not able to read firebase notification from postman

I am able to receive Notification from firebase notification panel but not from POSTMAN.
Here is the msg I am getting after using Postman

{"multicast_id":5932054590706775021,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1503475843250053%00000000f9fd7ecd"}]}

Here is the code I am using to handle it.

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if(remoteMessage.getData().size()>0){
        Log.e("main hoon","opened class wahi");
        Map<String, String> data = remoteMessage.getData();

        //you can get your text message here.
        String text= data.get("1");

        sendnoti(text);
    }


}

private void sendnoti(String body) {
   Intent i1=new Intent(this,MainActivity.class);
    i1.putExtra("word", body);
    i1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pi=PendingIntent.getActivity(this,0,i1,PendingIntent.FLAG_CANCEL_CURRENT);
    Uri ns=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder nb=new NotificationCompat.Builder(this).setSmallIcon(R.drawable.heart)
            .setContentTitle("Word Of the Day")
            .setContentText(body).setSmallIcon(R.drawable.heart)
            .setAutoCancel(true)
            .setSound(ns)
            .setContentIntent(pi);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0,nb.build());
}

}

but am not able to receive any notification I tried both variants.

{
"to":"AAAAD3Wencs:APA91bG5eLSH6zM_AD-CnJG5a16Cj6Ydt7AaoD_42Y3laDCEQ6DjW2b7Ve6HYKaDb0KpjKfVhnhctXpdSpajpT37jszF-LqYjm1ap57euGN5zr1l2Bg****************",
"data":{

    "1":"cold"
}

}

and

{
  "to": "AAAAD3Wencs:APA91bG5eLSH6zM_AD-
  CnJG5a16Cj6Ydt7AaoD_42Y3laDCEQ6DjW2b7Ve6HYKaDb0KpjKfVhnhctXpdSpajpT37jszF-
  LqYjm1ap57euGN5zr1l2BgjqOL***********",
  "notification": {
  "title" : "title",
  "body"  : "body text",
  "icon"  : "ic_notification"
   }
 }

But no luck please help

Upvotes: 1

Views: 164

Answers (2)

Bala K
Bala K

Reputation: 1

{
  "to" :"e6eN8oD709M:APA91bEhusv9OdIPwTuZhd-_-rp7oMLL5LO_4RA0Q99MLYMuf_hR9-DvI_oRRDxEXsnIjUiPLnccnRkjoUZtsMzSBy7bURj-vL5vVos7dQkr*****************",
  "notification" :
  {
    "body" : "This is a Firebase Cloud Messaging Topic Message!",
    "title" : "FCM Message"
  }
}

Try this

Upvotes: 0

phpdroid
phpdroid

Reputation: 1663

{
 "data":{
 "1": "gold"
        },
"to": "/topics/NEWS"
 }

worked for me

Upvotes: 2

Related Questions