Reputation: 982
The user of my app can create a custom list with parent and child items. I store these informations in a xml file. I would like to give the user the opportunity to share this file (Email etc.). If the other user clicks on this file I would like to open the app and show the data in my list!
What Ive done so far: The user can create a xml-file and save it in his storage. The problem now: How to open the app when clicked on the file? Do I have to create my own file extension that has the xml data inside?
EDIT:
<activity
android:name=".activities.TrainingSimpleShowActivity"
android:label="@string/title_activity_training_simple_show"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\\.xml"
android:mimeType="*/*" />
</intent-filter>
</activity>
Upvotes: 1
Views: 1077
Reputation: 4845
No, you just have to set an intent filter for your app.
For example:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xml" android:mimeType="*/*" />
</intent-filter>
So when a user clicks to open on XML file your app can be proposed to open this file from the Android system.
Then you have to get the Intent in your app and handle the data.
Intent intent = getIntent();
Uri data = intent.getData();
Maybe you can write a guideline to write this XMl file for you users, and when your app get the date from the intent you can search a particular tag or attribute.
Hope this help you.
UPDATE manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dojester13.experimentintent">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<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" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xml" android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 3