app-bundle-samples icon indicating copy to clipboard operation
app-bundle-samples copied to clipboard

Disambiguation dialog is shown when opening activity with URI

Open nhkarthick opened this issue 6 years ago • 10 comments

The project doesn't build in Android Studio version 3.4.1. So I downgraded the gradle version to 3.4.2 (com.android.tools.build:gradle:3.4.2).

Steps to repro

  1. Click REQUEST INSTALL SPLIT INSTALL VIA URL button
  2. An disambiguation dialog is shown with apps of the same package name.

Even tried running the project with Android Studio v3.5 with the project gradle version 'com.android.tools.build:gradle:3.5.0-rc02' the same issue exists.

Looking forward for help. Thanks

nhkarthick avatar Aug 05 '19 11:08 nhkarthick

I have the same problem, and created a simple repository to mimic my setup. Off course, when trying out this project, make sure you update the domain and packagename of the app, to reflect your assetlinks.json file

https://github.com/Entreco/Dynamic-feature-disambiguation/tree/master

Entreco avatar Aug 05 '19 21:08 Entreco

Found an open issue here in issue tracker. Our entire application depends on this URI intent navigation. This bug is complete show stopper on implementing dynamic feature.

@keyboardsurfer do you have any update on this fix? Any workaround do you suggest ?

Appreciate your help!

Karthi-R avatar Sep 05 '19 14:09 Karthi-R

I asked the same question on StackOverflow.

Until the issue is fixed, the suggested work-around is to:

So yes... I believe I have seen this before, it is some odd behavior when navigating from one dynamic-feature (instant) to another (non-instant) via a URL intent.

Until this gets addressed, I don't recommend using a URL intent to navigate between modules, instead, use reflection to directly get to the other module's activity, example:

if (doesModuleExist()) { val intent = Intent() .setClassName(getPackageName(), "com.sample.ProfileActivity") .addCategory(Intent.CATEGORY_DEFAULT) .addCategory(Intent.CATEGORY_BROWSABLE) startActivity(intent) }

Which basically means, to use URL intents only for starting your instant app/dynamic features. But navigation between features in your app, should use reflection

Entreco avatar Sep 05 '19 14:09 Entreco

@Entreco Thanks for your update!

we believe, using reflection is not a scalable solution. also it involves lot of code changes. Any quick workaround available on this ?

Karthi-R avatar Sep 05 '19 14:09 Karthi-R

Agreed that reflection feels wrong/ awkward. But that's the only work around I have heard so far.

Would be nice to get an update about this issue from people working on the project

Entreco avatar Sep 05 '19 14:09 Entreco

In order to launch an activity via URL without the disambiguation dialog you might have to call setPackage with your package name to handle the intent.

keyboardsurfer avatar Sep 06 '19 09:09 keyboardsurfer

I see the disambiguation dialog in my sample project: https://github.com/Entreco/Dynamic-feature-disambiguation

Calling setPackage does not seem to make a difference (at least with my setup, device and buildtools ):

val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://giddy.entreco.nl/viewer/"))
            .setPackage(packageName)
            .addCategory(Intent.CATEGORY_DEFAULT)
            .addCategory(Intent.CATEGORY_BROWSABLE)
        startActivity(intent)

Entreco avatar Sep 06 '19 09:09 Entreco

Thanks @keyboardsurfer for the quick response. As @Entreco mentioned; Calling setPackage doesn't fix this issue.

Karthi-R avatar Sep 06 '19 13:09 Karthi-R

Hi, Anyway to fix this issue ? @keyboardsurfer

NagendraHariKarthick avatar Nov 09 '20 09:11 NagendraHariKarthick

@NagendraHariKarthick I was facing the same issue, and found a possible solution: https://siebedatema.medium.com/dynamic-feature-navigation-with-deep-links-on-android-7d04b6fda10b

The important part is using this extention function:

fun Intent.convertToSafeDynamicFeatureModuleIntent(context: Context) {
    //Get list of all intent handlers for this Intent. This should only be the actual activity we are looking for
    val options = context.packageManager.queryIntentActivities(this, PackageManager.MATCH_DEFAULT_ONLY)
    //Set the activity that supported the given intent
    setClassName(packageName, options[0].activityInfo.name)
}

siebed avatar Jan 03 '21 19:01 siebed