javaandroidkotlinandroid-studioandroid-intent-chooser

How can I change the default app for opening a URI and enlist all the supported Android apps for this purpose?


Override the always-selected app by the user in Android Kotlin

Use case:
I parse the URL to intent in order to initialize the system to open the supported app by the user. Now user selects Firefox as always and whenever the user taps on the URL(to share as intent) it doesn't show any more all apps(e.g.: Firefox, Chrome, Edge, etc.) for a user to select again rather just using Firefox as the always remember by the android system.

Actual Problem To Solve:
Need to show all apps to users that support that URL rather than the always selected app the user selected somewhere. (e.g.: Firefox is default but I want all the supported apps in the system i.e.: Firefox, chrome to preview for the user to select)


Solution

  • You can override this behaviour by using the below code:

     val i = Intent(Intent.ACTION_VIEW)
                    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    i.data = Uri.parse(deepLinkUri)
    
    
                    // Create a chooser intent
                    val chooserIntent = Intent.createChooser(i, "Choose an app")
                    // Clear any previous default setting
                    chooserIntent.putExtra(
                        Intent.EXTRA_EXCLUDE_COMPONENTS,
                        arrayOf<ComponentName>()
                    )
                    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    startActivity(chooserIntent)