简体   繁体   中英

Firebase push notifications not showing up while app is in background (Emulator)

I send firebase push notification to a singe android device from the firebase console. This works well while the app is running in the foreground. I receive the event and onMessageReceived() is called. When the app is in the background I'm expecting to see an notification entry to show up in the system notification tray of the emulator. Instead I'm getting the error below and no notification is popping up on the device. My messages are very simple just the message text and the FCM token.

Update: It seems to be a emulator issue because on a real device it is working.

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 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)

Should use GCM high-priority messages to wake the app and access the network. Example of High priority GCM message:-

{
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
  "priority" : "high",
   "notification" : {
    "body" : "This week’s edition is now available.",
    "title" : "NewsMagazine.com",
    "icon" : "new",
  },
  "data" : {
    "volume" : "3.21.15",
    "contents" : "http://www.news-magazine.com/world-week/21659772"
  }
}

See the "priority" key has value "high", this will awake the device and gcm message will be delivered instantly and it wont crash.

Check this out for more information https://developer.android.com/training/monitoring-device-state/doze-standby.html#whitelisting-cases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM