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