通过意图从文件管理器中选择文件 [英] Select File from file manager via Intent

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

问题描述

我想做什么:

我想以文件的字符串形式获取路径,该路径是通过Android文件管理器选择的.

I wanna get the path as a String of a file, which I choose via an Android File Manager.

我所拥有的:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Open with ..."), FILE_SELECT_CODE);

这段代码对我来说几乎可以正常工作,但是有一个问题.我只能使用以下应用程序选择文件:

This code, works nearly fine for me, but there is one problem. I can only select my file with the following apps:

我的问题:

是否有人可以通过Android文件管理器选择任何文件?

Does anyone have a working code for choosing any file via the Android File Manager?

推荐答案

使用此:

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*"); 
    startActivityForResult(intent, REQUEST_CODE);

对于要打开文件管理器的三星设备,请使用以下命令:

For samsung devices to open file manager use this:

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);

有关更多参考,请参见 http://developer.android.com/guide/topics/providers/document-provider.html

For more reference checkout http://developer.android.com/guide/topics/providers/document-provider.html

这篇关于通过意图从文件管理器中选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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