我有一個自定義文件類型,擴展名爲.myext
。 我已閱讀Android文檔和許多SO貼文,以瞭解如何配置意圖過濾器將這些文件關聯到我的應用程序。它的工作原理但不正確。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:mimeType="application/*" />
<data android:pathPattern=".*\\.myext" />
<data android:host="*" />
</intent-filter>
然後它鏈接.myext
文件到我的應用程序,而且每一個沒有應用assoiated文件。所以我可以打開我不想要的.otherext
文件。
然後我發現這個答案https://stackoverflow.com/a/5097734/575481這表明有多個意圖過濾器,所以我得到:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.myext" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.myext" />
</intent-filter>
,但這似乎並沒有爲我工作。
我想要的是:我的應用程序只打開.myext文件。你有什麼主意嗎 ?
此外,我將需要打開一些其他文件分機(.myext1,.myext2),但我想一旦我得到適當的意圖過濾器,我只需要複製它的其他擴展名,對吧?