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

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

问题描述

我想为可以返回任何类型文件的应用程序启动一个Intentchooser

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天全站免登陆