Search code examples
androidperformanceandroid-intentintentfilterapplinks

Do not trigger the intent filter of same application from which an intent is fired


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


Solution

  • 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()