使用存储访问框架打开特定路径 [英] Open specific path using Storage access framework

查看:266
本文介绍了使用存储访问框架打开特定路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过使用意图打开 Files应用来编写文本文件.但是,当我通过意图打开文件"应用程序时,它是在打开下载路径",而我想打开一个特定路径.有可能吗?

I am able to write the text files by opening the Files app using the intent. But when I open the Files app through intent it is opening Downloads path instead I would like to open a specific path. Is that possible ?

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, CREATE_REQUEST_CODE);

我想使用Intent启动文件"应用程序,它应该打开特定的路径.我通过传递Uri尝试了 intent.setDataAndType ,但是它不起作用.

I would like to launch the Files app using Intent and it should open specific path. I have tried intent.setDataAndType by passing the Uri, but it is not working.

推荐答案

为了指示文档导航器的初始位置,您应该将此添加到您的意图中:

in order to indicate the initial location of documents navigator you should add this to your intent :

intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, your_initial_uri);

像这样:

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, your_initial_uri);
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, CREATE_REQUEST_CODE);

这篇关于使用存储访问框架打开特定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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