通过 Android 中的 Intent 选择任何类型的文件 [英] Pick any kind of file via an Intent in Android

查看:53
本文介绍了通过 Android 中的 Intent 选择任何类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为可以返回任何类型文件的应用程序启动一个意图选择器

I would like to start an intentchooser for apps which can return any kind of file

目前我使用(我从 Android 电子邮件源代码中复制的文件附件)

Currently I use (which I copied from the Android email source code for file attachment)

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "File");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);

但它只在我的 Galaxy S2 上显示画廊"和音乐播放器".此设备上有一个文件浏览器,我希望它出现在列表中.我还希望相机应用程序显示在列表中,以便用户可以拍摄照片并通过我的应用程序发送.如果我安装 Astro 文件管理器,它也会响应该意图.我的客户只是 Galaxy SII 的所有者,我不想强​​迫他们安装 Astro 文件管理器,因为他们已经有了一个基本但足够的文件管理器.

But it only shows "Gallery" and "Music player" on my Galaxy S2. There is a file explorer on this device and I would like it to appear in the list. I would also like the camera app to show in the list, so that the user can shoot a picture and send it through my app. If I install Astro file manager it will respond to that intent, too. My customers are Galaxy SII owners only and I don't want to force them to install Astro file manager given that they already have a basic but sufficient file manager.

知道如何实现这一目标吗?我很确定我已经看到默认文件管理器出现在这样一个菜单中来选择文件,但我不记得在哪个应用程序中.

Any idea of how I could achieve this ? I am pretty sure that I already saw the default file manager appear in such a menu to pick a file, but I can't remember in which app.

推荐答案

不是针对相机而是针对其他文件..

Not for camera but for other files..

在我的设备中,我安装了 ES File Explorer 并且这对我来说很有效..

In my device I have ES File Explorer installed and This simply thing works in my case..

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

这篇关于通过 Android 中的 Intent 选择任何类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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