且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法显示收到的Firebase快速入门示例消息通知

更新时间:2022-10-22 15:57:20

使用Firebase Cloud Messaging display-messages自动显示只有当应用程序不在前台(如它关闭或在后台)。

当应用程序在前台 onMessageReceived()方法将被调用,以允许开发人员在应用程序内部显示消息或自己生成通知。



这与数据消息(使用

{data:{...}} 有效载荷通过服务器端api发送的消息不同)总是调用 onMessageReceived()方法。


I'm trying out the Firebase Cloud Messaging Quickstart sample code (Android) from the following https://firebase.google.com/docs/samples

I managed to run the sample code, but when i try to send the notification from the Firebase console, despite i can see the notification content i sent in the logcat, but it didn't display in my Android Studio Emulator. There are few errors in the logcat.

I'm using Android Studio 2.1.1 Windows 64-bit Emulator Nexus_5x Android API 23

As i can see the notification in logcat, with payload as "hello 3"

05-30 15:13:25.746 2729-7428/com.google.firebase.quickstart.fcm D/MyFirebaseMsgService: From: 621412269084
05-30 15:13:25.746 2729-7428/com.google.firebase.quickstart.fcm D/MyFirebaseMsgService: Notification Message Body: hello 3

the token id was taken from below

05-30 15:09:14.229 2729-2729/com.google.firebase.quickstart.fcm D/MainActivity: InstanceID token:
d58dJBNq_-E:APA91bHd8ZnNmVfKmMIEwnYgcx-T77E8UwU_jrrZkC4WWoZ6uZ-2lL6Dg4zZEEMvtUs2V86VjnNogOcAZKa1LF7ICvxNrEuWADgsibXt_6XoKDVmAvmsAFrzmJM4l8_Q-DcbjhN55kEx

Few errors found in the logcat

05-30 15:12:06.967 2234-6271/com.google.android.gms I/EventLogChimeraService: Aggregate from 1464619326768 (log), 1464619326768 (data)
05-30 15:12:07.029 2234-6275/com.google.android.gms D/DropBoxEntryAddedChimeraService: User is not opted-in to Usage & Diagnostics.
05-30 15:12:07.070 2234-6276/com.google.android.gms D/DropBoxEntryAddedChimeraService: User is not opted-in to Usage & Diagnostics.
05-30 15:13:25.724 1866-2597/com.google.android.gms.persistent D/GCM: Error whitelisting app for waking in doze
                                                                      java.lang.reflect.InvocationTargetException
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at ott.a(SourceFile:49473)
                                                                          at ott.c(SourceFile:1366)
                                                                          at otn.b(SourceFile:638)
                                                                          at ahge.a(SourceFile:998)
                                                                          at ahgf.run(SourceFile:1070)
                                                                          at java.lang.Thread.run(Thread.java:818)
                                                                       Caused by: java.lang.SecurityException: Calling app u0a7 is not on whitelist
                                                                          at android.os.Parcel.readException(Parcel.java:1599)
                                                                          at android.os.Parcel.readException(Parcel.java:1552)
                                                                          at android.app.usage.IUsageStatsManager$Stub$Proxy.whitelistAppTemporarily(IUsageStatsManager.java:293)
                                                                          at android.app.usage.UsageStatsManager.whitelistAppTemporarily(UsageStatsManager.java:266)
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at ott.a(SourceFile:49473) 
                                                                          at ott.c(SourceFile:1366) 
                                                                          at otn.b(SourceFile:638) 
                                                                          at ahge.a(SourceFile:998) 
                                                                          at ahgf.run(SourceFile:1070) 
                                                                          at java.lang.Thread.run(Thread.java:818) 
05-30 15:13:25.735 2729-7429/com.google.firebase.quickstart.fcm I/FA: Tag Manager is not found and thus will not be used
05-30 15:13:25.746 2729-7428/com.google.firebase.quickstart.fcm D/MyFirebaseMsgService: From: 621412269084
05-30 15:13:25.746 2729-7428/com.google.firebase.quickstart.fcm D/MyFirebaseMsgService: Notification Message Body: hello 3
05-30 15:13:25.928 1200-1940/? D/WVCdm: Instantiating CDM.
05-30 15:13:25.929 1200-1602/? I/WVCdm: CdmEngine::OpenSession
05-30 15:13:25.929 1200-1602/? I/WVCdm: Level3 Library Sep 28 2015 13:08:28
05-30 15:13:25.930 1200-1602/? W/WVCdm: Could not read /data/mediadrm/IDM1013/ay64.dat2: No such file or directory
05-30 15:13:25.930 1200-1602/? W/WVCdm: Could not load liboemcrypto.so. Falling back to L3.  dlopen failed: library "liboemcrypto.so" not found
05-30 15:13:25.932 1535-2145/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
05-30 15:13:25.947 1200-1602/? I/WVCdm: CdmEngine::QueryKeyControlInfo
05-30 15:13:25.949 1200-1200/? W/WVCdm: BufferReader::Read<T> : Failure during parse: Not enough bytes (4)
05-30 15:13:25.949 1200-1200/? W/WVCdm: CdmEngine::ExtractWidevinePssh: Unable to read atom size.
05-30 15:13:25.949 1200-1200/? I/WVCdm: CdmEngine::GenerateKeyRequest
05-30 15:13:25.950 1200-1200/? D/WVCdm: PrepareKeyRequest: nonce=1125203836
05-30 15:13:26.041 1200-1991/? I/WVCdm: CdmEngine::CloseSession
05-30 15:13:26.061 1866-7431/com.google.android.gms.persistent I/PhenotypeFlagCommitter: Experiment Configs successfully retrieved for com.google.android.gms.playlog.uploader
05-30 15:13:26.062 1866-7431/com.google.android.gms.persistent I/GoogleURLConnFactory: Using platform SSLCertificateSocketFactory
05-30 15:13:26.086 1535-2728/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true

                                                                     [ 05-30 15:13:26.447  3544: 3557 D/         ]
                                                                     HostConnection::get() New Host Connection established 0xae428680, tid 3557
05-30 15:13:26.505 1535-1929/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
05-30 15:13:26.635 1535-1898/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
05-30 15:13:26.637 1535-1546/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
05-30 15:13:26.637 1866-7431/com.google.android.gms.persistent W/Uploader:  no longer exists, so no auth token.
05-30 15:13:26.777 1535-1546/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
05-30 15:13:26.977 1866-7432/com.google.android.gms.persistent W/GLSUser: [AppCertManager] IOException while requesting key: 
                                                                          java.io.IOException: Invalid device key response.
                                                                              at exx.a(SourceFile:267)
                                                                              at exx.a(SourceFile:2235)
                                                                              at exw.a(SourceFile:46)
                                                                              at exq.a(SourceFile:55)
                                                                              at exp.a(SourceFile:113)
                                                                              at com.google.android.gms.auth.account.be.legacy.AuthCronChimeraService.a(SourceFile:1054)
                                                                              at ovi.run(SourceFile:179)
05-30 15:13:32.163 2234-7537/com.google.android.gms D/DropBoxEntryAddedChimeraService: User is not opted-in to Usage & Diagnostics.

With Firebase Cloud Messaging display-messages are automatically displayed only when the application is NOT in foreground (like it's closed or in background).

When the application is in foreground the onMessageReceived() method will be called instead, to allow the developer to display the message inside the application or to generate a notification himself.

This is different from data-messages (messages sent via the server-side api with the
{"data": {...}} payload) which always invoke the onMessageReceived() method.