2012-01-18 74 views
1

我的清單:Android文件關聯

<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:scheme="http" android:host="*" android:pathPattern=".*mht" /> 
    <data android:scheme="https" android:host="*" android:pathPattern=".*mht" /> 
</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="message/rfc822" android:scheme="http" /> 
    <data android:mimeType="multipart/related" android:scheme="http" /> 
    <data android:mimeType="message/rfc822" android:scheme="https" /> 
    <data android:mimeType="multipart/related" android:scheme="https" /> 
</intent-filter> 

結果:

很好奇,不是嗎?我在這裏做錯了什麼?同樣怪異 - 我的清單:

<intent-filter 
    android:icon='@drawable/ic_launcher' 
     android:label='AndroidMHT File' 
    android:priority='1'> 
    <action android:name="android.intent.action.VIEW" /> 
    <action android:name="android.intent.action.EDIT" /> 
    <action android:name="android.intent.action.PICK" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:scheme="file" /> 
    <data android:scheme="content" /> 
    <data android:mimeType="*/*" /> 
    <data android:pathPattern=".*\\.mht" /> 
    <data android:host="*" /> 
</intent-filter> 

結果:

  • /mnt/SDCARD/Android/data/com.mht/files/flipie.mht < ---選擇器不顯示我的程序作爲一個選項
  • /mnt/SDCARD/Android/data/com.mht/files/keepme.mht < ---選擇器將顯示我的程序作爲一個選項

我在結束白衣。任何幫助非常感謝。

+0

好的,在這裏使用響應htt P://stackoverflow.com/questions/4675257/custom-filetype-in​​-android-not-working我能夠得到第二部分(SDCARD文件系統部分)工作。但是第一部分,HTTP部分不起作用。 – 2012-01-18 00:15:57

回答

6

在第一個答案的建議在這裏幫我:Android intent filter: associate app with file extension

這是我的新清單,對於那些誰可以從中受益:

<intent-filter 
    android:icon='@drawable/ic_launcher' 
     android:label='AndroidMHT File' 
    android:priority='1'> 
    <action android:name="android.intent.action.VIEW" /> 
    <action android:name="android.intent.action.EDIT" /> 
    <action android:name="android.intent.action.PICK" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:mimeType="*/*" /> 
    <data android:pathPattern="*.mht" /> 
</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:scheme="http" android:host="*" android:pathPattern=".*\\.mht" /> 
    <data android:scheme="https" android:host="*" android:pathPattern=".*\\.mht" /> 
</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="message/rfc822" android:scheme="http" /> 
    <data android:mimeType="multipart/related" android:scheme="http" /> 
    <data android:mimeType="message/rfc822" android:scheme="https" /> 
    <data android:mimeType="multipart/related" android:scheme="https" /> 
</intent-filter> 
+0

非常感謝@Authman ..我試圖做同樣的事情,研究很多,並嘗試了數百個Intent過濾器,但最後你的代碼工作..謝謝很多! – Kanika 2012-05-18 07:31:51

+0

=)不客氣。 – 2014-01-22 15:49:48

0

當檢索從您的網站中的文件,你能驗證哪些內容類型在這兩個文件?如果他們顯示不同的類型(可能Web服務器正在解釋數據並在每個文件中看到不同的觸發器),我會期待不同的行爲。

我查了一下頭在http://web-sniffer.net/,所以我不能比較的第二個文件不存在了。

,可能會影響事情的另一種皺紋 - 除非你設置用戶代理,以配合您的Android設備將使用什麼,你可能會在你的桌面瀏覽器或網絡嗅探器不同的結果。

不知道這是什麼原因導致您的問題,但它是值得驗證的。

+0

對不起。我只是把第二個文件備份。我點擊了GMail Android客戶端的鏈接,所以我不確定是否在啓動意圖之前檢查標題。但是,例如,如果我將keepme.mht複製到我的SD卡上並雙擊它,它會給我上下文菜單。但同一個網站鏈接keepme.mht不(我已經比較了dl'd文件的內容和原來的,他們是相同的) – 2012-01-18 00:30:45

+1

嗯。瀏覽器可能會執行一些檢查並根據數據確定內容類型。我看到這兩個文件使用了不同的字符集,這可能是相關的。第二個文件頂部還有一些額外的行。也許你需要做一些調查,看看它處理第二個文件的類型,並添加一個過濾器來捕獲它。 – ProjectJourneyman 2012-01-18 07:06:19

0

您可以嘗試更改下面的屬性

android:mimeType="text/*" 
android:pathPattern="*.mht" 

到您的意圖過濾器