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

时间:2016-05-30 16:39:07

标签: android firebase firebase-cloud-messaging firebase-notifications

我正在尝试以下https://firebase.google.com/docs/samples

中的Firebase云消息传递快速入门示例代码(Android)

我设法运行示例代码,但是当我尝试从Firebase控制台发送通知时,尽管我可以看到我在logcat中发送的通知内容,但它没有在我的Android Studio模拟器中显示。 logcat中的错误很少。

我使用的是Android Studio 2.1.1 Windows 64位 仿真器Nexus_5x Android API 23

我可以在logcat中看到通知,有效负载为"你好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

令牌ID来自下方

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

在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.

1 个答案:

答案 0 :(得分:0)

使用Firebase云消息传递仅当应用程序不在前台时才会自动显示显示消息(例如它已关闭或在后台)。

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

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