安卓:目录和文件选择Android的库 [英] Android: Directory and file chooser android library

查看:316
本文介绍了安卓:目录和文件选择Android的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的应用程序的Andr​​oid aFileChooser库项目选择从外部存储的文件。但它似乎并不只挑选,让用户选择下载位置,下载文件的目录。
有哪些支持挑文件,并选择目录中的任何Android的库项目?

I'm using aFileChooser android library project in my app to select the file from external storage. but it doesn't seem to pick only directory to let user select the download location to download the files. Is there any android library project which support both pick file and pick directory?

据我了解有多个问题已经在这里找到答案无论是对文件选择器或目录选择,但是经过大量的搜索我无法找到一个目录和文件选择。
任何帮助将是AP preciated。

I understand there are multiple questions have been answered here either for file chooser or directory chooser but after extensive search I couldn't find one for both directory and file chooser. Any help would be appreciated.

推荐答案

我没有Android的库项目,但你可以简单地做下一个code你自己的文件选择。这code会要求你选择了一个文件浏览器,当您选择在文件浏览器的文件,你会得到在文件路径字符串的onActivityResult功能的路径。

I have no android library project, but you can simply make your own file chooser with the next code. This code will ask you to chose a file browser, when you select a file in the file browser you'll get the path in the onActivityResult function in the FilePath String.

创建此公开:

private static final int ACTIVITY_CHOOSE_FILE = 3;

当点击一个按钮,你可以调用这个:

When a button is clicked you can call this:

            Intent chooseFile;
            Intent intent;
            chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
            chooseFile.setType("file/*");
            intent = Intent.createChooser(chooseFile, "Choose a file");
            startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);

您可以赶上这个$ C $目录c:

You can catch the directory with this code :

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) return;
        String path     = "";
        if(requestCode == ACTIVITY_CHOOSE_FILE)
        {
              Uri uri = data.getData();
              String FilePath = getRealPathFromURI(uri);

        }
    }

public String getRealPathFromURI(Uri contentUri) {
    String [] proj      = {MediaStore.Images.Media.DATA};
    Cursor cursor       = getContentResolver().query( contentUri, proj, null, null,null); 
    if (cursor == null) return null; 
    int column_index    = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

编辑:
如果你不想使用外部文件浏览器,可以导入这个Android库到您的项目:
HTTPS://$c$c.google.com/p/afiledialog/

这篇关于安卓:目录和文件选择Android的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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