2017-08-05 117 views
1

我有一個應用程序,我允許用戶備份數據,並希望他們能夠通過文件管理器,GMail點擊備份文件,和下載系統應用程序。Android:文件擴展名意圖過濾器無法與GMail/Downloads應用程序正常工作

我在清單文件中定義了以下意圖...

 <intent-filter 
      android:label="Simple Backup File" 
      android:priority="999" > 

      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.OPENABLE" /> 

      <data 
       android:scheme="http" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="https" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="ftp" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="ftps" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="content" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="file" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 
     </intent-filter> 

以上的作品,如果我點擊從文件管理器.sbu文件,但不能從下載的Gmail或Google列表。我確實讀過我需要mimeType才能使內容方案正常工作,但是當我將mimeType定義爲*/*application/octet-stream時,該功能甚至在文件管理器中停止工作。

我在做什麼不正確?第一次寫入文件時是否需要設置任何設置?你最好如何處理我的情況。

回答

0

我通過將內容放入其自己的意圖過濾器組以及文件數據方案來實現它,它們都具有MIME類型的應用程序/八位字節流。

 <intent-filter android:priority="999" > 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.OPENABLE" /> 

      <data 
       android:scheme="http" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="https" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="ftp" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="ftps" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="file" 
       android:host="*" 
       android:pathPattern=".*\\.sbu" /> 
     </intent-filter> 

     <intent-filter android:priority="999" > 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.OPENABLE" /> 

      <data 
       android:scheme="file" 
       android:mimeType="application/octet-stream" 
       android:pathPattern=".*\\.sbu" /> 

      <data 
       android:scheme="content" 
       android:mimeType="application/octet-stream" 
       android:pathPattern=".*\\.sbu" /> 
     </intent-filter> 
+0

這將打開任何和所有文件的Gmail附件。不只是sbu,但abc,xyz等。我無法弄清楚如何使它過濾Gmail文件擴展名? –

相關問題