我有一个应用程序,我得到某些数据,如日期,时间,队1和队2从体育应用程序接口,我想使用FCM来显示一个通知,每次(我的通知是为足球超级联赛的现场比赛,所以当游戏开始玩,通知应该弹出在用户应用程序中),有没有可能通过FCM发送数据到我的应用程序显示一个通知,我已经读了一点关于FCM HTTP V1,但我仍然不确定它是否做的工作,任何建议,伙计,谢谢。
发布于 2019-11-05 09:44:36
您可以将针对特定主题的JSON发送给订阅该主题的所有用户。您可以通过调用此方法订阅该主题中的用户
FirebaseMessaging.getInstance().subscribeToTopic("your_topic");订阅后,您可以将此JSON发送到https://fcm.googleapis.com/fcm/send接口
{
"to":"/topics/your_topic",
"notification": {
"title": "Title Message"
"body": "Body Message"
},
"data": {
"time": "your time"
"date": "your date"
"home_team": "your home team"
"away_team": "your away team"
}以及你的头文件"Content-Type", "application/json"和"Authorization", "key=your_FCM_legacy_server_key"
如何处理NotificationService上“数据”完全取决于您自己
这就是在JSON的这一部分中处理数据的方式
"data": {
"time": "your time"
"date": "your date"
"home_team": "your home team"
"away_team": "your away team"
}像这样处理它
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> data = remoteMessage.getData();
String time= data.get("time");
String date= data.get("date");
String home_team= data.get("home_team");
String home_away= data.get("home_away");
String body = remoteMessage.getNotification().getBody(); //retrieve the notification body
String title = remoteMessage.getNotification().getTitle(); //retrieve the notification title
}https://stackoverflow.com/questions/58702569
复制相似问题