Making an Android app look like a web browser

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:

  1. I have to look like a web browser to Android
  2. I have to implement the workaround
  3. 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.

This entry was posted in Technical and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *