MiuiChooserActivity: Failed to get target intent filter Android

56 views Asked by At

I want to open bottom dialog with sms default app, whatsapp and viber. Problem is with MIUI and Xiaomi with Android 13(+). It doesnt want to open Whatsapp app but opens sms default app. This is the error I got:

MiuiChooserActivity: Failed to get target intent filter
    android.content.IntentFilter$MalformedMimeTypeException: smsto:
        at android.content.IntentFilter.processMimeType(IntentFilter.java:904)
        at android.content.IntentFilter.addDataType(IntentFilter.java:842)
        at android.content.IntentFilter.<init>(IntentFilter.java:473)
        at com.android.internal.app.MiuiChooserActivity.getTargetIntentFilter(MiuiChooserActivity.java:2255)
        at com.android.internal.app.MiuiChooserActivity.queryDirectShareTargets(MiuiChooserActivity.java:2299)
        at com.android.internal.app.MiuiChooserActivity.onListRebuilt(MiuiChooserActivity.java:3173)
        at com.android.internal.app.MiuiResolverActivity.onPostListReady(MiuiResolverActivity.java:1404)
        at com.android.internal.app.ResolverListAdapter$2.run(ResolverListAdapter.java:502)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at android.app.ActivityThread.main(ActivityThread.java:8261)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)

This is my code:

        val whatsappIntent = createExplicitIntent("com.whatsapp", text)
        val viberIntent = createExplicitIntent("com.viber.voip", text)
        val smsIntent = createExplicitSmsIntent(text)

        val intentList = listOf(whatsappIntent, viberIntent, smsIntent)


        val filteredIntentList = intentList.filter { intent ->
            try {
                if (intent.type != null && intent.type?.startsWith("smsto:") == true) {
                    return@filter false
                }

                val resolveFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                    PackageManager.MATCH_DEFAULT_ONLY or PackageManager.MATCH_SYSTEM_ONLY
                } else {
                    PackageManager.MATCH_DEFAULT_ONLY
                }

                val activities = packageManager.queryIntentActivities(intent, resolveFlags)

                activities.isNotEmpty()
            } catch (e: Exception) {
            
                false
            }
        }.distinctBy { it.`package` }


        if (filteredIntentList.isNotEmpty()) {
            // Create a chooser intent
            val chooserIntent =
                Intent.createChooser(filteredIntentList.first(), "Choose a messaging app")
            chooserIntent.putExtra(
                Intent.EXTRA_INITIAL_INTENTS,
                filteredIntentList.subList(1, filteredIntentList.size).toTypedArray()
            )

I also found this on stackoverflow to check if its MIUI :

fun isMIUI(context: Context): Boolean {

    val intentList = listOf(
        Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.ACTION_SEND),
        Intent().setComponent(ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
        Intent("miui.intent.action.POWER_HIDE_MODE_APP_LIST").addCategory(Intent.ACTION_SEND),
        Intent().setComponent(ComponentName("com.miui.securitycenter", "com.miui.powercenter.PowerSettings"))
    )
    intentList.forEach { intent ->
        val resolved = resolveActivityList(context, intent).isNotEmpty()
        if (resolved) return true
    }
    return false
}

But I still didnt manage to call Whatsapp properly.

0

There are 0 answers