Monday 1 April 2013

Problems with the intent filter in the Trailer application for Android

As I wrote in my previous post, I had some trouble setting up an intent filter which worked for the Trailer Android application.  In my initial release, v1.0, I found a way of creating an intent filter which made the Trailer app handle .tqz files when sent as email attachments, but I found that this filter was too permissive, and Trailer also finished up being offered as a handler for lots of other kinds of content.

I've now released an updated version v1.0.1 which has a filter which I regard as correct (but with an important disclaimer which you will be able to a few paragraphs later in this post).

During my research on this topic on the internet, I could see that I was not the only person having problems with this particular aspect of Android development.  The Stack Overflow site contained quite a lot of material on the topic, but I didn't find any of the recipes there worked quite the way I expected, although when I finally worked out what was going wrong the material I had read on SO started to make sense.

The final filter I decided to use looked like this:
    <activity android:name=".TrailerMainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </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="file"/>
        <data android:scheme="content"/>
        <data android:scheme="http"/>
        <data android:host="*"/>
        <data android:mimeType="application/tl-trailer"/>
      </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="file"/>
        <data android:host="*"/>
        <data android:mimeType="*/*"/>
        <data android:pathPattern=".*\\.tqz"/>
      </intent-filter>
    </activity>

This fragment has three intent filters, of which the first one is related to launching the application from its icon on the Android desktop, the second one relates to launching in a context where a MIME type is available, and the third one relates to recognition of the .tqz file extension once a file with that extension is available on the device.

I am now convinced in my own mind that the configuration above is a reasonably correct one (not necessarily the only configuration which would work). Unfortunately this configuration does not presently work in the Gmail application provided with my Android device (a Nexus 7 running Android 4.2.2), but it does work in the Email application. According to this issue in the Android Open Source Project bug database, I'm not the only person who thinks this is a bug in the Android Gmail application, but the response on the issue from the developers is to refer the poster to the Google Mobile application forum, which doesn't seem to have a publicly accessible bug reporting interface, and may mean that there is not much hope of a resolution from Google any time soon.

Anyway, please feel free to try out v1.0.1 of the application, but don't expect .tqz files received as email attachments under the Gmail app to be automatically handled by Trailer.  My recommendation is to use the separate Android Email application instead.

Trailer application for Android updated

I've just released an updated version of the Trailer application for Android&trade;.

The purpose of this new application is to introduce a change to a part of the Android application configuration called the 'intent filter'.  Android applications have a configuration file called 'AndroidManifest.xml' which, among other things, controls the conditions under which applications are launched when attachments they can handle are received over the web, email etc.

When working on the original application version, I had a lot of trouble setting up an intent filter which worked as I wanted, e.g. when an email contains an attachment which has a filename ending in '.tqz', the Android operating system should provide the Trailer application as one of those which are offered
to handle the file.  In the end, I found a combination which worked, but after release of v1.0 I discovered that the filter was a bit too permissive, and the Trailer application was being offered to handle a wider range of things than was intended (including all emails).

Anyway, the new release is intended to fix this, please contact me if you are having problems with it.

I suspect that the problem I was having may not just affect me, so I plan to write up a technical description of the fix I have come up with in case it is useful to other people.