无法读取邮递员的 Firebase 通知

Posted

技术标签:

【中文标题】无法读取邮递员的 Firebase 通知【英文标题】:Not able to read firebase notification from postman 【发布时间】:2017-08-23 08:32:25 【问题描述】:

我能够从 firebase 通知面板接收通知,但不能从 POSTMAN 接收通知。这是我在使用 Postman 后收到的消息

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

这是我用来处理它的代码。

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());



但我尝试了这两种变体时无法收到任何通知。


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

    "1":"cold"




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

但运气不好,请帮忙

【问题讨论】:

你在为Content-Type: application/json设置一个标题吗? 是的,我正在设置@BobSnyder 【参考方案1】:

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

为我工作

【讨论】:

【参考方案2】:

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

试试这个

【讨论】:

以上是关于无法读取邮递员的 Firebase 通知的主要内容,如果未能解决你的问题,请参考以下文章

函数返回未定义,预期Promise或值和通知长时间延迟

如何在使用firebase作为服务器或数据库的cordova应用程序中实现通知

Firebase TypeError:无法读取未定义的属性“val”

FCM - 推送通知仅适用于控制台而不适用于邮递员

无法在 Firebase 函数中读取 null 的属性

firebase云函数错误TypeError:无法读取未定义的属性“子”