Cannot open custom file extension

不想你离开。 提交于 2019-12-23 08:56:13

问题


I have a file format I wish to support, it's just a zip but I've renamed it .amg so my app can read it.

On my samsung phone with gingerbread it works fine and it opens.

On my motorola phone with kitkat all I get is can not open it.

I've tried various solutions found here but none seem to work.

Typically I copy the file into the download folder on the phone and click the file.

The only thing that works on kitkat is if I open the file using Astro File Manager, but I can't force that app on people. So what's wrong that makes Astro work but nothing else?

    <activity
        android:name="com.test.StartupActivity"
        android:label="@string/app_name"
        android:theme="@style/backdropTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:host="*" />
            <data android:mimeType="*/*" />
            <data android:scheme="file" />
            <data android:pathPattern=".*\\.amg" />
        </intent-filter>
    </activity>

** [EDIT] ****** If I use Astro file manager in kitkat it seems to work. So Astro works, the three other ones I've tried including built in one doesn't but with gingerbread it always works.

However, on my kitkat when I try and open the file I get the following exception: invalid stored block lengths.


回答1:


If you take a look at logcat, when attempting to open an email attachment etc you can see how the content is resolved. And you'll notice that the mimeType is application/octet-stream. Notice that I don't set the scheme as that is implied by pathPattern to be file | content. Here is the filters I use for gpx files:

<intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:mimeType="application/octet-stream"
                android:host="*"
                android:pathPattern=".*\\.gpx" />
        </intent-filter>  

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:mimeType="application/gpx"
                android:host="*"
                android:pathPattern=".*\\.gpx" />
        </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:host="*"
                android:pathPattern=".*\\.gpx" />
        </intent-filter>


来源:https://stackoverflow.com/questions/21744539/cannot-open-custom-file-extension

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