MIUI - Permission denied while trying to start ACTION_SEND / ACTION_VIEW intent

920 Views Asked by At

I faced an issue, which occurs only on MIUI devices. I am trying to share some text using the following code

 private fun shareTextWithCallback(text: String) {
        val title = getString(resId)

        val intent = Intent(Intent.ACTION_SEND)
            .putExtra(Intent.EXTRA_TEXT, text)
            .setType("text/plain")

        val receiver = Intent(requireContext(), ShareCompletedReceiver::class.java)

        val pendingIntent = PendingIntent.getBroadcast(requireContext(), 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT)

        val chooser = Intent.createChooser(intent, title, pendingIntent.intentSender)

        startActivity(chooser)
}

And on MIUI devices after the item has been selected from intent chooser, nothing happens. That's what I found in the log:

2020-11-30 12:33:15.526 782-1085/? D/com.android.server.am.ExtraActivityManagerService:
MIUILOG- Permission Denied Activity :
Intent { act=android.intent.action.SEND typ=text/plain flg=0xb080001 
cmp=org.telegram.messenger/org.telegram.ui.LaunchActivity clip=MY_TEXT_HERE .... }

The same happens when I simply try to send ACTION_VIEW intent:

fun Fragment.showBrowser(link: String) {
    val intent = Intent(Intent.ACTION_VIEW).apply { data = Uri.parse(link) }
    startActivity(intent)
}
D/com.android.server.am.ExtraActivityManagerService:
MIUILOG- Permission Denied Activity :
Intent { act=android.intent.action.VIEW dat=LINK... flg=0x3000000 
cmp=com.android.chrome/com.google.android.apps.chrome.IntentDispatcher }

I've searched throughout similar questions, but they were all about starting activity from the background (e.g. broadcast receiver), which is not the case in my situation. Thanks for your help in advance

1

There are 1 best solutions below

0
On

On MIUI, your app muse be accepted "Displaying popup windows while running in the background" permission on App detail settings. That permission will allow you start the activity on background enter image description here