A Rundown of Android Intent Selectors: Building Intents Correctly
Article Summary
Jack Webb from ASOS discovered a common Android Intent mistake that could trap users in infinite loops. Most developers use ACTION_VIEW to open URLs, but there's a critical flaw hiding in plain sight.
When building a fallback to open ASOS's website in a browser, Webb hit a bizarre bug: the intent kept opening the ASOS app instead, creating an endless loop. The culprit? ACTION_VIEW is too generic and doesn't distinguish between browsers and apps with deep links. The solution involves a lesser-known Android feature: Intent Selectors.
Key Takeaways
- ACTION_VIEW finds any app that can handle a URI, not just browsers
- Apps with deep links intercept browser intents for their registered domains
- Intent Selectors let you target specific app types using two intents
- Create empty browser intent with CATEGORY_BROWSABLE and http: scheme as selector
- Selector property combines targeted apps from first intent with URL from second
Critical Insight
Using Intent Selectors with CATEGORY_BROWSABLE and an empty http: scheme ensures links always open in actual browsers, not apps with deep link handlers.