Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RemoteServiceException crashing my app on MIUI 11

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?

like image 498
crysxd Avatar asked Jan 10 '21 07:01

crysxd


People also ask

How to troubleshoot MIUI 11 connectivity issues?

Here are some troubleshooting steps to try to resolve connectivity issues, including Wi-Fi, Mobile Data, and Hotspot problems on MIUI 11: Enable Airplane mode and disable it after a minute. Reset APN. Reboot your phone and router. Reset Network Settings. Reset device to factory settings. For other things, you can just wait for updates. 7.

How to fix Xiaomi WebView keep crashing?

Settings > Apps > Manage Apps > Search for “WebView” > App Info > Uninstall updates. Xiaomi also recommends doing the same for the Google Chrome browser. So if you continue facing crash issues even after the above, then you may follow a similar series of steps for Chrome as well.

Does MIUI 11 have a GPS issue?

Luckily, on Android 10, you can limit access to Location Services. However, MIUI 11 seemingly has an issue with third-party apps with GPS readings that are not precise at all. Especially with Google Maps that barely work for some users.

Is Xiaomi’s MIUI 11 coming soon?

Ever since Xiaomi’s first handsets, their custom Android skin, MIUI, has been a hit or miss. In late October of 2019, Xiaomi started pushing MIUI 11, intended to initially stick to Android 9 Pie while Android 10 iterations were expected in the first quarter of 2020.


Video Answer


2 Answers

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.

like image 97
星星瑶 Avatar answered Sep 21 '22 10:09

星星瑶


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.

like image 31
mayank1513 Avatar answered Sep 20 '22 10:09

mayank1513