我如何使Android浏览器下​​载特定扩展名的文件? [英] How do I permit the android browser to download files of a particular extension?

查看:137
本文介绍了我如何使Android浏览器下​​载特定扩展名的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有默认的A​​ndr​​oid浏览器能够下载文件的特定文件扩展名的,名为.xyz,例如

I want to have the default android browser be able to download files of a particular file extension, .xyz, for example.

在没有安装天文(或其他文件管理器),用户将收到错误无法下载,不支持的内容在这部手机上。安装天文应用程序允许Android浏览器中的任何文件下载到SD卡。

Without installing Astro (or some other file manager), users will get the error "Cannot download. The content is not supported on this phone". Installing the Astro application allows the android browser to download any file to the sdcard.

它是如何做到的?我不希望我的应用程序的用户必须下载天文,而是只让操作系统或浏览器知道它的好下载与扩展名为.xyz文件,因为我的应用程序会处理它们。

How does it do that? I don't want users of my app to have to download Astro, but rather, just let the OS or browser know that it's okay to download files with the extension .xyz, because my app will handle them.

推荐答案

适当的条目添加到清单为您回应 ACTION_VIEW 意图该类型的文件。例如,该过滤器是为了游玩,可以查看PDF文件:

Add the appropriate entries to the manifest for you to respond to ACTION_VIEW Intents for that type of file. For example, this filter is for an activity that can view PDF files:

        <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="application/pdf" />
        </intent-filter>

通过适当的&lt;数据&GT; 元素,你可以从字面上看为名为.xyz 的文件,但我认为它会更好,如果你可以看为一个MIME类型来代替。

With an appropriate <data> element, you could literally watch for .xyz files, though I think it will be better if you can watch for a MIME type instead.

这篇关于我如何使Android浏览器下​​载特定扩展名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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