I’m not in the business of writing web browsers, but my HTC One X has a problem: HtcLinkify. Due to an annoying lawsuit from Apple, HTC changed the behavior of web links on their devices.Â Instead of jumping right into a specific app, the web browser just dumbly follows the link itself.Â There is a way to fix, but you have to root your phone.
Before you go any farther, there is a quick, non-rooting solution to the problem: Just use Chrome (or its beta) — it pulls in the smarts I detail below and things go back to working like magic.
For example, on your average Android device, if you click on this Play Store link, or this Google Maps link, you will go to the Play Store app, or the Google Maps app, respectively.Â On many HTC devices, however, you get to go a pale imitation in the form of a webapp, because the browser does not dereference those links like it should.Â Total sad face.Â Like, for sure.
“Great!” I thought to myself, I’ll write a little app that uses the “Detection and Migration” workaround and solve this problem for me, nice and easy.Â Some hurdles to solve:
- I have to look like a web browser to Android
- I have to implement the workaround
- I have to seamlessly pass URLs around that I don’t need to work around.
The first was tricky, intent documentation is out there, but it’s scattered across several different locations (and probably more; though that last one may have gotten me through them all had I started there).Â I got a kickstart by following this short article but still my app wouldn’t show up in the App Associations settings for web browsers.Â Then I decided to spy on the built-in browser itself with the handy (and no-permissions, nice) Package Explorer.Â The trick is that I had to indicate that my app was capable of surfing the web.Â Combining them both, here’s the interesting bit to the manifest:
<activity Â android:name="com.muddyhorse.unlinkify.MainActivity" Â android:label="@string/app_name" > Â <intent-filter> Â Â <action android:name="android.intent.action.MAIN" /> Â Â Â Â Â <category android:name="android.intent.category.LAUNCHER" /> Â Â Â Â Â <category android:name="android.intent.category.APP_BROWSER" /> Â Â Â </intent-filter> Â Â Â <intent-filter> Â Â Â Â Â <action android:name="android.intent.action.VIEW" /> Â Â Â Â Â <category android:name="android.intent.category.DEFAULT" /> Â Â Â Â Â <category android:name="android.intent.category.BROWSABLE" /> Â Â Â Â Â <data android:scheme="http"/> Â Â Â Â Â <data android:scheme="https"/> Â Â Â </intent-filter> Â </activity>
With that, I could masquerade as a web browser.Â In short order, I had myself launching from GoogleNow, and the world was great.
The second problem was pretty simple, the workaround article gives you the code.Â Now, my code was catching those URLs, and popping up an intent browser, and I was seeing the apps in my list that I expected!Â Awesome.
The last problem, then.Â I couldn’t use the simple intent browser all the time.Â I would need to remember the selection after the first time and I’d need to avoid the workaround altogether in simple non-captured cases.Â Code, but not a lot of it, probably.
At this point, I took a quick detour.Â Did the built-in browser app even bounce out to my Unlinkify app?Â Nope.Â Ugh.Â Maybe more intent digging, but I wasn’t even sure if that was possible.Â I needed to know about every URL so that I could arbitrate whether we needed to bounce out to a different app.
Then, I set Chrome as my default browser app, to see if it had the same behavior.Â It turns out, it already catches and dispatches the URLs correctly!Â Or, it does at least for Google apps.Â It’d be worth finding out if they just did specific workarounds, or if Chrome has the general solution I was pursuing.
So, things come to an inauspicious end, then, where the fire of my development activity stopped due to the fact that a good-enough solution is out there.Â Ah, well, my phone works better now.
Why was this even a problem for me if I had Chrome all along?Â For some reason I don’t recall, I didn’t want to “clutter” my Chrome instance with all those one-off tabs and searches.Â I left the default browser as the default, even though I used Chrome daily.Â I know, doesn’t make sense to me either.