[英]Firebase onMessageReceived returns no getNotification
Calling remoteMessage.getNotification()
returns null and when calling remoteMessage.getData()
I get a strange object back that has an initial property _wp={ as listed below.调用
remoteMessage.getNotification()
返回 null 并且在调用remoteMessage.getData()
时我得到一个奇怪的 object 返回,它有一个初始属性_wp={如下所示。 I need to extract the alert property each time but I am not sure how.我每次都需要提取警报属性,但我不确定如何。
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
RemoteMessage.Notification notification = remoteMessage.getNotification();
Map<String, String> data = remoteMessage.getData();
Log.d("DATA", remoteMessage.getData().toString());
sendNotification(data);
}
The remote data log returns the below.远程数据日志返回以下内容。 So I can't seem get the title and text I need to in order to construct my notification.
所以我似乎无法获得构建通知所需的标题和文本。
{_wp={"c":"01euntvtna3epk83","alert":{"text":"Body text","title":"test"},"receipt":false,"type":"simple","targetUrl":"wonderpush:\/\/notificationOpen\/default","n":"01eunu08bjla8303","reporting":{"campaignId":"01euntvtna3epk83","notificationId":"01eunu08bjla8303"},"receiptUsingMeasurements":true}, alert=Body text}
I basically want to use them with when using the NotificationCompat.Builder我基本上想在使用 NotificationCompat.Builder 时使用它们
.setContentTitle(title)
.setContentText(text)
Any help will be greatly appreciated.任何帮助将不胜感激。 Thank you very much in advance.
非常感谢您提前。
It is normal that remoteMessage.getNotification()
returns null
as WonderPush only uses FCM notifications with data inside them, nothing in the Firebase's own format. remoteMessage.getNotification()
返回null
是正常的,因为 WonderPush 仅使用带有数据的 FCM 通知,而 Firebase 自己的格式没有任何内容。
remoteMessage.getData()
returns you with a map that can only store String values. remoteMessage.getData()
会返回一个 map,它只能存储字符串值。 This corresponds to the top-level JSON payload.这对应于顶级 JSON 有效负载。 This map's fields are the top-level JSON object fields, and its values are all stringified.
该映射的字段是顶级的 JSON object 字段,其值都是字符串化的。 So you'll have to parse the
_wp
key using new JSONObject(remoteMessage.getData().get("_wp"))
.因此,您必须使用
new JSONObject(remoteMessage.getData().get("_wp"))
解析_wp
键。 You'll basically read the title
and text
fields of this parsed _wp
JSON object to feed .setContentTitle()
and .setContentText()
of the NotificationCompat.Builder
.您将基本上阅读此已解析的
_wp
JSON object 的title
和text
字段,以提供NotificationCompat.Builder
的.setContentTitle()
和.setContentText()
。
But you should note that the WonderPush Android SDK is precisely here for that purpose:但是您应该注意,WonderPush Android SDK 正是为此目的而出现的:
_wp.alert
field: https://github.com/wonderpush/wonderpush-android-sdk/blob/v4.0.2/sdk/src/main/java/com/wonderpush/sdk/AlertModel.java_wp.alert
字段的代码: https://github.com/wonderpush/wonderpush-android-sdk/blob/v4.0.2/sdk/src/main/java/com/wonderpush/sdk/AlertModel .java If you have an addition, it would make more sense to fork, hack, submit a pull request, and use your fork in the meanwhile.如果你有一个补充,那么分叉、破解、提交拉取请求并同时使用你的分叉会更有意义。
Best,最好的,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.