Registering a specific file-type handler on Android

(My example is in C# since I was working with Mono for Android but the same is applicable for Java applications as well via the usual manifest XML)

While many answers already exist on forums and several tutorials are available, I’ve still encountered a certain problem when I tried to register a handler for my own file type (let’s call it .xyz). I’ve added an IntentFilter attribute, specifying that I’m handling the View and Edit actions and choosing the Default category.
Since there is no existing MIME type for my extension I’ve used DataPathPattern for filtering and a wildcard for DataHost.
Overall the code looked like that

[IntentFilter(new[]{Intent.ActionView, Intent.ActionEdit},
Categories=new[]{Intent.CategoryDefault},
DataPathPattern=".*\.xyz",
DataHost="*")]
public class MyActivity : Activity { ...

The problem is that my application was now taking over all possible intents such as calling and messaging, and when I was browsing my contacts my application icon showed there as a possible candidate for handling the contact entry (i.e. making the call). What finally solved the problem was specifying the DataMimeType as “application/octet-stream”, like that

[IntentFilter(new[]{Intent.ActionView, Intent.ActionEdit},
Categories=new[]{Intent.CategoryDefault},
DataPathPattern=".*\.xyz",
DataHost="*", DataMimeType="application/octet-stream")]
public class MyActivity : Activity { ...

Leave a Reply

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