9

I started receiving a weird crashes from MIUI 11 devices running Android 11 (so far only Mi 10 and Mi 10 lite 5G). I think this is a platform issue and nothing in my app as it's super specific to Xiaomi Android 11.

Fatal Exception: android.app.RemoteServiceException
Bad notification(tag=null, id=3249) posted from package de.crysxd.octoapp, crashing app(uid=10334, pid=23788): Couldn't inflate contentViewsjava.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification$MessagingStyle android.app.Notification$MessagingStyle.setConversationType(int)' on a null object reference

I know similar crashes can happen if you e.g. use SVG icons on old devices, but I already use PNG. There are only two types of notification the device shows, one is a foreground service and one comes from Firebase. From the timing of the crash, it seems unlikely to be the Firebase notification.

Here is the code I use to create to notification (here in full):

private fun createProgressNotification(progress: Int, title: String, status: String) = createNotificationBuilder()
        .setContentTitle(title)
        .setContentText(status)
        .setProgress(maxProgress, progress, false)
        .setOngoing(true)
        .addCloseAction()
        .setNotificationSilent()
        .build()

    private fun createCompletedNotification(name: String?) = createNotificationBuilder()
        .setContentTitle(getString(R.string.notification_print_done_title))
        .apply {
            name?.let {
                setContentText(it)
            }
        }
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
        .build()

    private fun createDisconnectedNotification() = createNotificationBuilder()
        .setContentTitle(getString(R.string.notification_printing_lost_connection_message))
        .setContentText(lastEta)
        .setProgress(maxProgress, 0, true)
        .addCloseAction()
        .setOngoing(false)
        .setNotificationSilent()
        .build()

    private fun createInitialNotification() = createNotificationBuilder()
        .setContentTitle(getString(R.string.notification_printing_title))
        .setProgress(maxProgress, 0, true)
        .setOngoing(true)
        .addCloseAction()
        .setNotificationSilent()
        .build()

    private fun createNotificationBuilder() = NotificationCompat.Builder(this, notificationChannelId)
        .setColorized(true)
        .setColor(ContextCompat.getColor(this, R.color.primary_light))
        .setSmallIcon(R.drawable.ic_notification_default)
        .setContentIntent(createStartAppPendingIntent())

Anyone having the same issue or knows a solution?

crysxd
  • 3,177
  • 20
  • 32
  • I'm getting the same issue from the same device but I have no clue where this comes from, could you reproduce it? – georkost Jan 27 '21 at 10:15
  • No, I did not have any progress. I know it's related to Xiaomi's Android 11 update. I don't know whether it's device specific or will affect all Xiaomi devices with Android 11 (let's hope not) – crysxd Jan 27 '21 at 13:00
  • Thanks for the answer, you can have a look here, I've found this [article](https://piunikaweb.com/2021/01/25/android-11-update-bugs-issues-problems-tracker/) containing a bug tracker table at the bottom. Seems like they indeed have issues with notifications with Android 11 update. – georkost Jan 27 '21 at 13:15
  • Any news on this? My app is also affected by this issue. – Orange Feb 15 '21 at 11:50
  • Nope...still crashing :D – crysxd Feb 15 '21 at 19:18

2 Answers2

2

My previous answer is hidden. Update the system to MIUI 12.2.7 and then got the crash. I have a notification to update per second in my app and the crash only happens sometimes after the app keeps running for a while.

星星瑶
  • 159
  • 2
  • 7
  • I am bit confused with this answer. Could someone explain why this is happening and what to do to prevent this crash? – kotoMJ Jan 19 '21 at 21:48
  • Nope...I can confirm though that I have a similar setup. My app shows a long running notification (potentially days) from a foreground service. So maybe it's somehow related to that? I have no clue...and I feel like there is not much we can do besides hoping Xiaomi fixes this on their end – crysxd Jan 27 '21 at 13:02
1

Looking at the error, the app is crashing because of a null pointer exception.

Fatal Exception: android.app.RemoteServiceException
Bad notification(tag=null, id=3249) posted from package de.crysxd.octoapp, crashing app(uid=10334, pid=23788): 

Couldn't inflate contentViewsjava.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification$MessagingStyle android.app.Notification$MessagingStyle.setConversationType(int)' 
on a null object reference

I would suggest you to use Log class to find out on which line the error is occurring.

For now you can wrap your notification code in try... catch block and log the error in the catch block. This will prevent your app from crashing, which is better.

This approach will help you understand the issue better and fix it or at least make it work with some limited functionality at least, which is better than crashing the app.

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
  • 3
    The code is invoked from the system, not my app. It's also exclusive to the mentioned Xiaomi Android verison. – crysxd May 03 '21 at 09:42