2014-06-18 27 views
0

我有一個自定義文件類型,擴展名爲.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),但我想一旦我得到適當的意圖過濾器,我只需要複製它的其他擴展名,對吧?

回答

1

我明白了。在我的情況下,我試圖從電子郵件中獲取一個.ppp文件,並且它正在獲取任何文件。 這是工作濾波器

<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="content" android:pathPattern=".*\\.ppp" android:mimeType="application/ppp"/> 
     </intent-filter> 

您的活動的onCreate把一個斷點,並檢查

getIntent() 

專門MDATA應該給你什麼爲Android寫:方案和M型寫什麼爲android.mimeType

相關問題