无法打开自定义文件扩展名。

8
我有一个文件格式需要支持,它只是一个zip文件,但我将其重命名为.amg,以便我的应用程序可以读取它。
在我的三星手机上,使用姜饼系统时它可以正常工作并打开。
在我的摩托罗拉手机上,使用KitKat系统时,我只能得到无法打开的提示。
我尝试了这里找到的各种解决方案,但似乎都不起作用。
通常我会将文件复制到手机的下载文件夹中,然后点击该文件。
唯一在KitKat系统上有效的方法是使用Astro文件管理器打开该文件,但我无法强制让其他人使用该应用程序。那么,是什么原因使Astro可以工作而其他应用程序却不行?
    <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>

如果我在Kitkat中使用Astro文件管理器,它似乎可以正常工作。因此Astro可以工作,但我尝试过的其他三个包括内置的文件管理器都不能正常工作,但在Gingerbread中它总是有效的。
然而,在我的Kitkat上,当我尝试打开文件时,出现以下异常:无效的存储块长度。

我认为问题可能出在pathPattern上。在摩托罗拉设备上,“AMG”文件所在的路径中是否包含句点?这可能会导致问题。看一下这个人为了做类似于你的事情而经历的繁琐过程的例子:https://github.com/bpellin/keepassdroid/blob/master/AndroidManifest.xml - robnick
也许可以帮助你:https://dev59.com/0Gw05IYBdhLWcg3wykvn#7102838 - Marco Acierno
我已经尝试过了:( 这肯定是个常见的事情,为什么有这么多解决方案,却找不到任何官方的解决方法呢?路径只是/storage/sdcard0/download/file.amg. - Neil Walker
请查看此链接:https://dev59.com/hFPTa4cB1Zd3GeqPiViq - Chintan Khetiya
我不确定你在这里的意思是什么--“如果我在kitkat中使用Astro文件管理器,它似乎可以工作。所以Astro可以工作,但我尝试过的其他三个应用程序(包括内置的应用程序)不能在gingerbread上工作。”请解释得更清楚一些。至于你的下一个问题,“我收到了以下异常:无效的存储块长度。”---这通常发生在文件损坏时,请在其他设备上使用相同的文件并告诉我它是否有效? - Ajay S
显示剩余2条评论
1个回答

1
如果您查看logcat,尝试打开电子邮件附件等,您可以看到内容是如何解决的。您会注意到mimeType是application/octet-stream。请注意,我没有设置方案,因为路径模式暗示为file | content。这是我用于gpx文件的过滤器:
<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>

谢谢!MimeType与扩展名在所有文件上都能很好地工作! - adruzh
有没有想法如何向应用程序发送启动参数/或者它是如何发送的?我想加载从应用程序启动的URL(通过单击项目文件加载项目)。 - Lealo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接