使用 Intent.ActionOpenDocumentTree 时,您可以允许用户保存在设备外的位置吗? [英] When using Intent.ActionOpenDocumentTree can you allow the user to save in a location off the device?

查看:20
本文介绍了使用 Intent.ActionOpenDocumentTree 时,您可以允许用户保存在设备外的位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个 Xamarin 项目,但我认为代码主要只是包装了 android sdk.当我选择一个文件时,我使用/得到这个:

This is a Xamarin project but I think the code mostly just wraps the android sdk. When I pick a file I use/get this:

var intent = new Intent(Intent.ActionGetContent);
intent.AddCategory (Intent.CategoryOpenable);
StartActivityForResult (Intent.CreateChooser (intent, "Select file"), 0);

注意它是如何从远程位置打开的.但是当我尝试选择一个目录时,我使用/得到这个:

Notice how it is capable of opening from remote locations. But when try to pick a directory I use/get this:

// https://stackoverflow.com/questions/27889377/action-open-document-tree-only-returns-empty-recent-folder
var intent = new Intent(Intent.ActionOpenDocumentTree);
intent.PutExtra("android.content.extra.SHOW_ADVANCED", true);
intent.PutExtra("android.content.extra.FANCY", true);
intent.PutExtra("android.content.extra.SHOW_FILESIZE", true);
StartActivityForResult (Intent.CreateChooser (intent, "Select Save Location"), 0);

我是否遗漏了什么或没有办法做到这一点?例如,在选择保存位置时,我希望用户能够选择 Prime Photos(如果有).

Am I missing something or is there no way to do this? For example, when choosing the save location I would like for the user to be able to choose Prime Photos if they have that.

推荐答案

这些 Intent 使用不同的 API

These intents use different APIs

  • ACTION_GET_CONTENT is the older one (since API level 1).

ACTION_OPEN_DOCUMENT_TREE 是存储访问框架的一部分在 API 级别 19 中引入.不幸的是,我知道的任何 SAF 提供程序都不支持此意图,而不是事件 Google Drive.据我所知,它仅用于访问本地存储(android.content.extra.SHOW_ADVANCED 是一个未公开的额外显示内部存储根目录)

ACTION_OPEN_DOCUMENT_TREE is part of the Storage Access Framework introduced in API level 19. Unfortunately this intent is not supported by any SAF provider I know of, not event Google Drive. As far as I know it is only used to access local storage (android.content.extra.SHOW_ADVANCED is an undocumented extra showing the internal storage root)

虽然没有像人们希望的那样广泛实施,但 SAF 仍然可用.您可以使用:

While not as widely implemented as one would like, the SAF is still usable. You can use :

  • ACTION_CREATE_DOCUMENT if you want to save a single document (as opposed to let the user choose a subtree where you can write multiple documents or create subdirectories)
  • ACTION_OPEN_DOCUMENT to select an existing document.

有关详细信息,请参阅使用存储访问框架打开文件.

See Open files using storage access framework for more details.

这篇关于使用 Intent.ActionOpenDocumentTree 时,您可以允许用户保存在设备外的位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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