gpt4 book ai didi

android - getNotification().getBody() 失败

转载 作者:行者123 更新时间:2023-12-03 22:54:02 25 4
gpt4 key购买 nike

我正在尝试从 google firebase 通知消息中提取消息。

这是我的代码:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{

Log.d("FROM", "From: " + remoteMessage.getFrom() );
sendNotification(remoteMessage.getNotification().getBody());
}
remoteMessage.getFrom()remoteMessage.getNotification().getBody() 时返回正确的值崩溃并显示以下日志:
.example.mturky.testfirebase W/dalvikvm: threadid=16: thread exiting with uncaught exception (group=0x4199ccf8)
05-29 18:26:09.886 15436-15583/com.example.mturky.testfirebase W/dalvikvm: threadid=16: uncaught exception occurred
05-29 18:26:09.887 15436-15583/com.example.mturky.testfirebase W/System.err: java.lang.NullPointerException
05-29 18:26:09.887 15436-15583/com.example.mturky.testfirebase W/System.err: at com.example.mturky.testfirebase.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:31)
05-29 18:26:09.888 15436-15583/com.example.mturky.testfirebase W/System.err: at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source)
05-29 18:26:09.888 15436-15583/com.example.mturky.testfirebase W/System.err: at com.google.firebase.messaging.FirebaseMessagingService.zzn(Unknown Source)
05-29 18:26:09.888 15436-15583/com.example.mturky.testfirebase W/System.err: at com.google.firebase.messaging.FirebaseMessagingService.zzm(Unknown Source)
05-29 18:26:09.888 15436-15583/com.example.mturky.testfirebase W/System.err: at com.google.firebase.iid.zzb$2.run(Unknown Source)
05-29 18:26:09.888 15436-15583/com.example.mturky.testfirebase W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-29 18:26:09.889 15436-15583/com.example.mturky.testfirebase W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-29 18:26:09.889 15436-15583/com.example.mturky.testfirebase W/System.err: at java.lang.Thread.run(Thread.java:841)
05-29 18:26:09.889 15436-15583/com.example.mturky.testfirebase W/dalvikvm: threadid=16: calling UncaughtExceptionHandler
05-29 18:26:09.890 15436-15583/com.example.mturky.testfirebase E/AndroidRuntime: FATAL EXCEPTION: pool-4-thread-1
Process: com.example.mturky.testfirebase, PID: 15436
java.lang.NullPointerException
at com.example.mturky.testfirebase.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:31)
at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source)
at com.google.firebase.messaging.FirebaseMessagingService.zzn(Unknown Source)
at com.google.firebase.messaging.FirebaseMessagingService.zzm(Unknown Source)
at com.google.firebase.iid.zzb$2.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

知道如何解决吗?

最佳答案

要扩展我在该问题下发布的评论:
remoteMessage.getNotification().getBody()仅当您发送 时可用通知消息 .使用firebase控制台或server-api
有效载荷 = { "notification" : { "body" : "my body"} }
如果您要发送 数据消息 喜欢 { "data" : { "mykey" : "myvalue"} }那么在客户端你应该使用方法:remoteMessage.getData()

关于android - getNotification().getBody() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37512889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com