2016-08-18 78 views
0

我想寫一個意圖過濾器,這將允許我的應用程序打開擴展名爲「.mathref」的文件。以下的建議here,我寫我的過濾器是這樣的:Android電子郵件意圖過濾器沒有過濾文件擴展名

 <!-- For email attachments --> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="application/*" host="*" /> 
      <data android:pathPattern=".*\\.mathref"/> 
      <data android:scheme="content" /> 
     </intent-filter> 

但是,它沒有過濾!也就是說,如果用戶點擊他們電子郵件中的任何文件,而不管其擴展名爲何,它會列出我的應用程序作爲打開文件的選項。

我該如何解決這個問題?

+0

你爲什麼稱這是一個電子郵件意圖過濾器?它與電子郵件有關。 – greenapps

回答

0

其實,question you linked has the answer

在提供的代碼中,有評論有:

<!-- 
Capture content by MIME type, which is how Gmail broadcasts 
attachment open requests. pathPattern and file extensions 
are ignored, so the MIME type *MUST* be explicit, otherwise 
we will match absolutely every file opened. 
--> 

the MIME type *MUST* be explicit,你有你的設置爲application/*將匹配一切

0

我怎麼能修復?

你不知道。不要求contentUri具有任何特定的文件擴展名。同樣,不要求Web瀏覽器中的URL具有任何特定的文件擴展名。與Web瀏覽器一樣,Android更依賴於MIME類型。

如果您希望Web服務器知道使用某種MIME類型提供您所需的文檔格式,或者您希望郵件客戶端知道爲您的文檔格式附件使用特定的MIME類型,請使用該MIME輸入你的<intent-filter>,而不是application/*

否則,請接受任何Uri作爲輸入,並驗證內容是否爲您需要的文檔格式。或者,不要執行ACTION_VIEW

相關問題