How to make your Android app open xml or custom files?

Hi,

I would like to associate my game with xml files, so when I try to open one on my Android mobile (through file browser or email attachments) my game would be in the list of available apps to do it.

This looks like a very basic question to me, however I can’t find a proper answer. I found several related topics on different forums/blogs but nothing that explains exactly how to do it.

My best shot is to add an intent filter in my AndroidManifest.xml file:

<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:mimeType="*/*" />
   <data android:pathPattern=".*\\.xml" />   
   <data android:host="*" />
</intent-filter>

But it doesn’t work… so right now I’m lost as I don’t know if there’s something wrong in my filter, or if it’s not at the right place in the manifest, or if I’m simply missing something asside from that.

Thanks for your help, any input would be great!

Here’s my complete manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:theme="@android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0" package="com.SunsetBits.BreakReturns" android:installLocation="preferExternal">
  <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.unity3d.player.UnityPlayerNativeActivity" android:screenOrientation="sensorPortrait">
      <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:mimeType="*/*" />
		  <data android:pathPattern=".*\\.xml" />   
		  <data android:host="*" />
		</intent-filter>
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
    <activity android:name="com.google.example.games.pluginsupport.SignInHelperActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.google.example.games.pluginsupport.SelectOpponentsHelperActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.google.example.games.pluginsupport.InvitationInboxHelperActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\ 592577814120" />
    <meta-data android:name="com.google.android.gms.appstate.APP_ID" android:value="\ 592577814120" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-feature android:name="android.hardware.touchscreen" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

Ok, I found this article that gives plenty of details and examples: http://www.vogella.com/tutorials/AndroidIntent/article.html

My filter was wrong but at the right place.
Here’s how it look in the end:

<intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="application/xhtml+xml" />
</intent-filter>

For information: using the mime type “text/xml” was working great for the SEND action, but not for the VIEW one, I don’t know why…

Also, I used the appplication “ManifestViewer” with “Simple XML Viewer” to see what was wrong. In their manifest they specify both “application/xhtml+xml” and “text/xml” mime types. However I didn’t see any differences with or without “text/xml” so I removed it in my manifest.

I hope this will help others.

My initial goal was to make it work with a custom file extension, I’ll continue from there and if I manage to do it I’ll add my solution in the comments.