关联特定文件扩展名,以我的Andr​​oid应用程序 [英] Associating certain file extension to my android application

查看:92
本文介绍了关联特定文件扩展名,以我的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦我的自定义文件扩展名关联到我,我开发Android应用程序。在我的Andr​​oid清单文件我有以下几点:

I'm having trouble associating my custom file extension to my android application that I am developing. In my android manifest file I have the following:

<data android:scheme="file" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />
<data android:scheme="content" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />  

这有点儿工作。让我解释。我在我的Gmail(发送一个文件给我自己),它具有正确的扩展名的文件,所以当我从我的手机浏览器下载并点击打开,它正确地打开我的应用程序,但如果我探索的文件路径;该文件的位置,并尝试打开它,我的电话说,没有应用程序可以打开此文件类型。

It kinda works. Let me explain. I have a file in my gmail( sent a file to my self ), which has the proper extension, so when I download it from my phone's browser and click open, it opens my application correctly, but if I explore to that file path; where the file is located, and try to open it, my phone says no application can open this file-type.

在如何解决这个问题的任何想法?

Any ideas on how to solve this problem?

推荐答案

一些情况下有点棘手,我已经决定使用:

Some cases are kinda tricky, I've settled on using:

    <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="file" />                               
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.myFileExt" />
        <data android:host="*" />
    </intent-filter>

和这有时会失败,因为有时只是一个更加全球化的MIME类型(在我的情况下,XML)的使用:

and this sometimes fails because sometimes only a more global mime type (in my case XML) is used:

    <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="text/xml" />
    </intent-filter>

这篇关于关联特定文件扩展名,以我的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆