【问题标题】:How to add Internal and External storage to File Chooser in android如何将内部和外部存储添加到 android 中的文件选择器
【发布时间】:2018-06-25 16:24:47
【问题描述】:

我的示例应用程序是打开文件选择器并选择文件/目录,然后将路径放入 EditText,我尝试了 question 中的方法并得到了这个结果

    public class MainActivity extends AppCompatActivity {
    private Button browse;
    private EditText editTextPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        browse = (Button) findViewById(R.id.browse);
        editTextPath = (EditText) findViewById(R.id.path);
        browse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                startActivityForResult(Intent.createChooser(intent,"Select file or dir"), 1);
                setResult(Activity.RESULT_OK);
            }
        });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
            String Fpath = data.getDataString();
            editTextPath.setText(Fpath);
        }

    }
}

我想将这样的内部和外部存储添加到文件选择器

【问题讨论】:

  • 这是 Lolipop 对话框,现在已更改为较新的版本,并且还支持 Google Drive。 metactrl.com/docs/sdcard-on-lollipop
  • @matio 谢谢它现在已经出现了,我不想在编辑文本中获得完整路径,因为这段代码没有得到逻辑路径,请参阅这张图片i.imgur.com/PkakUbn.png
  • 如果这是您的答案,请在评论中将其视为“此评论添加了一些有用的东西”。然后用你想要的东西创建另一个线程,我会在那里提供帮助。

标签: android android-intent android-activity filechooser android-afilechooser


【解决方案1】:

用户可以点击操作栏中的“...”提示并选择“显示内部存储”以显示这些选项。

没有官方支持 ACTION_GET_CONTENTACTION_OPEN_DOCUMENT 自动显示内部存储选项,但希望有一天会支持。

【讨论】:

  • 但我在某些应用程序中看到此选项显示内部和外部“SD 卡像这样
    i.stack.imgur.com/ag5pR.png>
  • 为什么不将它添加到您的答案中,它比“没有官方支持(它)”有用得多
  • @TimRae:因为在正式支持之前(并希望成为 CTS 的一部分),它是不可靠的。
【解决方案2】:

你必须使用Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); 安装Intent intent = new Intent(Intent.ACTION_GET_CONTENT );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 2016-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    相关资源
    最近更新 更多