1

I have a scenario where my app will catch a particular URL(call primary URL) through an intent filter and send this URL to an API which gives me a secondary URL and based on this secondary URL I will navigate the user to an in-app destination however when the API fails or when there is no in-app destination the want the user to be redirected to web

However, When I try to redirect the user to the web using the primary URL. My intent filter is being triggered again and it is giving the option to open the link in my app (which my app is not capable to handle). Things get worse when the user selects to open the link with my app always (in the android prompt). My app always tries to catch the URL and it goes into an infinite loop

How to remedy this

Nari
  • 333
  • 5
  • 13

1 Answers1

1

You can query the PackageManager and ask it to return you a list of all the possible applications that can handle the link. Then you can find another appropriate app in the list (exclude your own app). If there is only one app then you can launch it directly yourself, otherwise you will either need to choose one or ask the user to choose an app to open it.

See PackageManager.queryIntentActivities()

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • How do i exclude my own app from the list – Nari Aug 26 '19 at 10:12
  • Loop through the list and ignore your own app – David Wasser Aug 26 '19 at 12:19
  • 1
    Loop through the returned list of `ResolveInfo` objects and ignore your app's entry. You can tell your app's entry by comparing `ResolveInfo.activityInfo.packageName` to your own app's package name that you have in `AndroidManifest.xml` – David Wasser Aug 26 '19 at 12:23