2016-06-20 16 views
0

私のアプリのユーザーは、親項目と子項目を含むカスタムリストを作成できます。これらの情報はxmlファイルに保存されます。このファイル(メールなど)を共有する機会を に伝えたいと思います。他のユーザーがこのファイルをクリックすると、アプリを開いてリストにデータを表示したいと考えています。Android XMLファイルを共有して開く

私がこれまで行ってきたこと: ユーザーはxmlファイルを作成し、彼のストレージに保存することができます。 今問題:ファイルをクリックするとアプリを開く方法は? xmlデータを内部に持つ独自のファイル拡張子を作成する必要がありますか?

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> 

答えて

1

いいえ、あなたは自分のアプリのためのインテントフィルタを設定する必要があります。例えば

:ユーザーはアプリがAndroidのシステムからこのファイルを開くことを提案することができますファイルをXMLに開くようにクリックして閲覧

<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> 

次に、あなたのアプリケーションにインテントを取得し、データを処理する必要があります。

Intent intent = getIntent(); 
Uri data = intent.getData(); 

はたぶん、あなたはあなたのユーザーのために、このXMLファイルを書き込むためのガイドラインを作成することができ、あなたのアプリが意図から日付を取得するときには、特定のタグや属性を検索することができます。

ご希望の場合はこちらをご覧ください。私はマニフェストにインテントフィルタを配置する必要があります

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> 
+0

? – XxGoliathusxX

+0

manifest.xmlで、データを処理するアクティビティの中で、このケースでは私が思うようにメインです。 https://developer.android.com/guide/components/intents-filters.html –

+0

文書を確認することをお勧めします。それを処理したいアクティビティに追加しました。しかし、私がXMLファイルをクリックし、 "open with ..."と言うと、リストに自分のアプリケーションが表示されません。 – XxGoliathusxX

関連する問題