Android File Associations

∥☆過路亽.° 提交于 2019-12-13 18:28:48

问题


My Manifest:

<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>

Results:

  • http://authman.net/keepme.mht <--- chooser does not display my program as an option
  • http://authman.net/flipcode.mht <--- chooser displays my program as an option

Very curious, no? What am I doing wrong here? Equally as weird -- my manifest:

<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>

Results:

  • /mnt/SDCARD/Android/data/com.mht/files/flipie.mht <--- chooser does not display my program as an option
  • /mnt/SDCARD/Android/data/com.mht/files/keepme.mht <--- chooser displays my program as an option

I'm at ends whit. Any assistance much appreciated.


回答1:


The suggestions in the first answer here helped me: Android intent filter: associate app with file extension

This is my new manifest, for those who may benefit from it:

<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>



回答2:


When retrieving the files from your web site, can you verify what the content types are in the two files? I would expect different behavior if they showed a different type (maybe the web server is interpreting the data and seeing different triggers in each file).

I checked the headers at http://web-sniffer.net/, and the second file doesn't exist anymore so I can't compare.

Another wrinkle that might affect things - unless you set the user agent to match what your Android devices will be using, you might get a different result on your desktop browser or web-sniffer.

Not sure if that's what is causing your problem, but it's worth verifying.




回答3:


You can try changing the below attributes

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

to your intent-filter



来源:https://stackoverflow.com/questions/8903443/android-file-associations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!