- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望 SAF“在指定文档中启动导航器,如果它是一个文件夹”(他们在文档中这样调用它)。
这不起作用,所以我也想知道我是否可以将存储快捷方式添加到 SAF UI。请参阅此链接中的图片: https://i.imgur.com/yGtcGMM.jpg
但我认为在特定文件夹中启动 SAF UI 的可能性更大,所以我暂时可能会采用这种方法。我已经在 onCreate(...)
方法中试过了:
String pathAsString = Environment.getExternalStorageDirectory() + "/myscientificapp/measurements/";
File pathAsFile = new File(pathAsString);
if (pathAsFile.exists()) { Log.d(TAG, "pathAsFile exists!"); } //This is printed in Logcat
android.net.Uri pathAsUri = Uri.fromFile(pathAsFile);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pathAsUri); //Does not make effect
startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
问题是它不起作用.. 或者我不知道该怎么做。 :/
我已经阅读了一些关于这些地方的信息。例如在 Medium.com开发人员说:
When selecting a location to save a file using ACTION_CREATE_DOCUMENT or when opening a document, the new EXTRA_INITIAL_URI allows you to override the default initial location (the last location the user selected) with your own custom starting location.
在 Android 文档中我们可以读到这个 EXTRA_INITIAL_URI :
Callers can set a document URI through DocumentsContract#EXTRA_INITIAL_URI to indicate the initial location of documents navigator. System will do its best to launch the navigator in the specified document if it's a folder, or the folder that contains the specified document if not.
我们也可以在 DocumentsContract#EXTRA_INITIAL_URI 上阅读它。 :
EXTRA_INITIAL_URI
...
Sets the desired initial location visible to user when file chooser is shown.
...
Location should specify a document URI or a tree URI with document ID. If this URI identifies a non-directory, document navigator will attempt to use the parent of the document as the initial location.
The initial location is system specific if this extra is missing or document navigator failed to locate the desired initial location.
高度抽象语言的所有荣耀,但我想至少了解一些有关如何使用此功能的详细信息。
但是在 Stackoverflow 上,一些开发人员告诉我们 it will not work .
还有一些threads are not really answered yet .
所以根据一些消息来源,它应该可以工作。
知道如何在 SAF UI 中创建快捷方式的人(见图片)?或者如何使用例如 ACTION_CREATE_DOCUMENT 使 SAF“在指定文档中启动导航器(如果它是一个文件夹)”? (如果我没记错的话,例如 Windows 95 中就存在这些功能 :> )
编辑:正如@A Jar of Clay 所暗示的那样,我删除了一些指向 git-project 的链接,因为最终“链接失效”。
我也尝试将树 Uri(如@CommonsWare 推荐的那样)从 ACTION_OPEN_DOCUMENT_TREE 传递到方法 intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pathAsTreeUri);
。但是 SAF 并没有从我作为 Uri 传递的位置开始。 :(
最佳答案
这answer Alex Baker 为我工作,我认为它也适用于你。
DocumentFile file = DocumentFile.fromTreeUri(context, uri);
intent.putExtra(EXTRA_INITIAL_URI, file.getUri());
您从 ACTION_OPEN_DOCUMENT_TREE 获得的 resultData.getData() 是您在 fromTreeUri() 中开始的 uri。
看起来像“位置应该指定文档 URI 或带有文档 ID 的树 URI”。 “带有文档ID”似乎是必不可少的。我可以直接使用 ACTION_OPEN_DOCUMENT 中的 resultData.getData() 并且它有效。直接将 resultData.getData 与 ACTION_OPEN_DOCUMENT_TREE 结合使用不起作用,但在上述过程之后起作用。
无论如何,对我有用,希望对你也有用。
关于android - 如何更好地控制 Android SAF UI(例如 ACTION_OPEN_DOCUMENT)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54257922/
在我的应用程序中,我想为用户提供一种从应用程序的数据目录中选择文件的方法。这是我的代码: // use ACTION_OPEN_DOCUMENT because ACTION_GET_CONTENT
我想在我的小米设备上使用 ACTION_OPEN_DOCUMENT。我试过 this google sample ,但它也不起作用。使用下面的代码,我可以正常运行在 Samsung galaxy s4
我正在使用此处指定的新 Kitkat 存储访问框架 (SAF): https://developer.android.com/guide/topics/providers/document-provi
我想使用作为存储访问框架的一部分提供的 android 系统对话框打开文件。我用 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); in
我有 AddActivity,它可以让您从相机拍摄的照片或从图库中选择的图像中获取 URI。然后就可以去DetailsActivity查看图片了。在您重新启动设备之前,我现在可以正常工作。在您重新启动
我想在特定路径打开文件选择器。用户应该能够选择手机上的任何文件,但 SAF 应首先显示特定文件夹。我尝试了以下方法,但它总是打开下载文件夹。谢谢! Intent intent = new Intent
我想获取我使用 Intent.ACTION_OPEN_DOCUMENT 选择的文件的文件扩展名。如何获取? 这就是我启动选择器的方式: private void startFilePicker(){
我很难理解 ACTION_OPEN_DOCUMENT 和 ACTION_GET_CONTENT Intent 用于打开可打开文档时之间的区别。如果我在 KitKat 之前支持 Andriod,它不支持
我尝试附上一些照片(或其他!文档),这些照片是通过手机相机(或其他!应用程序 - 用于创建文档)制作的。如果我运行下面的代码来选择照片,我没有看到它们: Screenshot from the App
当我尝试使用打开 .json 文件时 startActivityForResult(Intent(Intent.ACTION_OPEN_DOCUMENT).apply { addCategor
我正在使用 ACTION_OPEN_DOCUMENT Intent 来启动系统文件选择器。用户应该选择一个“gpx”文件(blabla.gpx)。 我希望选择器只允许选择带有“.gpx”扩展名的文件。
当用户选择文件夹而不是文件时,我希望能够从 DocumentFile 访问文件列表。我这样称呼 Intent : Intent intent = new Intent(Intent.ACTION_OP
我正在使用 android pie 中的 Retrofit 制作个人资料照片更改功能。 这样我就成功的把相机拍的照片上传到服务器了。但我不知道如何将从图库中选择的照片传输到我的服务器。(我可以使用 J
我希望 SAF“在指定文档中启动导航器,如果它是一个文件夹”(他们在文档中这样调用它)。 这不起作用,所以我也想知道我是否可以将存储快捷方式添加到 SAF UI。请参阅此链接中的图片: https:/
我需要编写一个 Android 应用程序来观察另一个应用程序何时修改文件,然后从中读取数据。该文件由用户选择。所以我想使用 Intent 以及设备上可用的文件选择器供用户选择文件。 使用 Intent
我正在尝试编写一个自定义 DocumentsProvider,它允许其他应用程序对其提供的 Uris 获取持久权限 我有一个 DocumentsProvider,我在我的 AndroidManufes
在我的一个 android 项目中,我在装有 Android 5.0.2 的三星平板电脑上遇到了以下问题:从 fragment 中,用户可以开始选择一个文件: private static final
我正在使用 react-native-firebase和 react-native-document-picker我正在尝试关注 face detection tutorial . 尽管通过 Perm
我是一名优秀的程序员,十分优秀!