question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A certain model of device cannot parse the payload of the data message.

See original GitHub issue
  • Android Studio version: 4.1.3
  • Firebase Component: Cloud Messaging
  • Component version: 21.1.0

Most models can work normally, but a user’s device crashed because it could not parse the payload of the data message.

This is the code.

class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        if (remoteMessage.data.isNotEmpty()) {
            val notificationType = remoteMessage.data.getValue("notification_type").toInt()
        }
    }
}

This is the payload when I pass the parameters to https://fcm.googleapis.com/fcm/send.

{
   "data":{
      "notification_type":1
   },
   "to":"xxxxxxxxxxx"
}

I get the report from Crashlytics.

report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
RoyDengcommented, Jun 4, 2021

@chliangGoogle I found that I did not receive the same crash from the same device in the past two days. Thank you.

1reaction
RoyDengcommented, Jun 1, 2021

Here is the payload when I pass the parameters to https://fcm.googleapis.com/fcm/send.

{"data":{"notification_type":1,"subscription_id":"627","subscription_title":"侯友宜","ref":"ae56de687328d21cc42b168a637c66ff","is_collected":false,"title":"[討論] 真的覺得陳其邁對防疫觀念很有s...","summary":"乃至於現在嚴格稽查『傳統市場』\n\n都很認真\n\n然後在施打疫苗方面\n\n陳其邁在『三...","content":"現在這樣看下來\n\n各地方首長之間互相比較一下\n\n陳其邁真的算...","src":"PTT","ch":"政黑板","author":"chungrew","url":"https://www.ptt.cc/bbs/HatePolitics/M.1622515747.A.044.html","senti":"負面","pt":"主文","stype":"BBS","cc":0,"lc":0,"dc":0,"sc":0,"time":"2021-06-01 10:49","is_sound_opened":true},"to":"xxxxxxxxxx"}

Here is the code in onMessageReceived.

class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        if (remoteMessage.data.isNotEmpty()) {
            val notificationType = remoteMessage.data.getValue("notification_type").toInt()

            when (notificationType) {
                0 -> {
                    val isSoundOpened = remoteMessage.data.getValue("is_sound_opened").toBoolean()
                }
                1 -> {
                    val isSoundOpened = remoteMessage.data.getValue("is_sound_opened").toBoolean()
                }
                2 -> {
                    val isSoundOpened = remoteMessage.data.getValue("is_sound_opened").toBoolean()
                }
                3 -> {
                    val isSoundOpened = remoteMessage.data.getValue("is_sound_opened").toBoolean()
                }
            }
        }
    }
}

Here is the report from Firebase Crashlytics.

Fatal Exception: java.util.NoSuchElementException: Key notification_type is missing in the map.
       at kotlin.collections.MapsKt__MapWithDefaultKt.getOrImplicitDefaultNullable(MapWithDefault.kt:24)
       at kotlin.collections.MapsKt__MapsKt.getValue(Maps.kt:344)
       at tw.keypo.app.fcm. MyFirebaseMessagingService.onMessageReceived(KEYPOFirebaseMessagingService.kt:20)
       at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@21.1.0:13)
       at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@21.1.0:8)
       at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@21.1.0:3)
       at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@21.1.0:3)
       at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@21.1.0:1)
       at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(:6)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.3.0:6)
       at java.lang.Thread.run(Thread.java:764)

This report is currently only received on Samsung Galaxy J6 (Android 8.0), and no problem with the emulator used in Android Studio.

Unfortunately, I do not own this type of device, and it comes from a customer.

I tried to find an image file and install it to the emulator to reproduce this problem, but Samsung’s official website does not provide an image file of this model.

https://developer.samsung.com/galaxy-emulator-skin/overview.html

For business purposes, I receive an average of 130 crash reports a day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Device returning JSON error · Issue #246 · codetheweb/tuyapi
So it might be the payload.
Read more >
Common AWS IoT Events issues and solutions
See the following section to troubleshoot errors and find possible solutions to resolve issues with AWS IoT Events. Errors. Detector model creation errors ......
Read more >
Could not parse request body into json: Unexpected character ...
I am missing a comma after the income line. Here is another example. Could not parse request body into json: Unexpected character (\'}\'...
Read more >
Failed to parse json data? | Apple Developer Forums
use JSONDecoder().decode. to parse data. {"aaa": "value", "bbb": 1}. it generated error: Unexpected error: dataCorrupted(Swift.DecodingError.
Read more >
Common CSV Template Error Messages and How to Fix Them
An error message that begins “Failed to parse file” indicates that the uploaded CSV file is invalid in some way. Watershed supports UTF-8 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found