Android 11:如何/在何处写入应在卸载后仍然存在的混合媒体文件 [英] Android 11: How/where to write mixed media files that should survive uninstall

查看:159
本文介绍了Android 11:如何/在何处写入应在卸载后仍然存在的混合媒体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个针对Android 11的特定用例相机应用.当我点击记录时,我想在某个地方创建一个新目录(其名称基于时间戳等),其中包含生成的视频以及一个在记录过程中也会写入的其他自定义YAML/JSON/CSV文件的整个堆(逻辑上属于记录的输出").

I am writing a specific use-case camera app that targets Android 11. When I hit record I would like to create a new directory somewhere (with a name based on the timestamp etc) that contains the resulting video as well as a whole heap of other custom YAML/JSON/CSV files that also get written during the recording process (belongs logically to the "output" of the recording).

我希望所有生成的文件都可以在应用程序卸载/重新安装后继续存在,因为我不想冒险让用户在卸载应用程序时丢失他们曾经记录的所有内容.如何使用Android 11中的新范围存储更改等来实现此目的?

I would like all of the generated files to survive an app uninstall/reinstall as I do not want to risk users losing everything they've ever recorded if they uninstall the app. How do I do this with the new scoped storage changes etc in Android 11?

在概述此处,我可以看到:

  • 应用特定文件应用偏好设置数据库显然不适合,因为这些文件无法在卸载后幸存下来
  • 文档和其他文件使用Storage Access Framework,但这并不适合,因为每次您要编写内容时都需要系统文件选择器.这会中断录制/用户体验的流程,并且没有任何相机应用程序能像这样工作.
  • 数据集/BlobStoreManager (此处)也不适合我的用例.
  • MediaStore API 看起来应该是它,但是就生成整个输出目录(包括自定义YAML/JSON/CSV文本文件)而言,它似乎并不能满足我的要求,所有这些都属于同一个人.我的目的是使用户在任何时候都可以简单地转到文件资源管理器,导航到适当的文件夹,然后将带有录音的文件夹复制到他们的计算机或其他任何东西上,以保存/查看数据.即使MediaStore.Files似乎也不能保证如果您的应用程序使用范围存储,您实际上可以做到这一点.
  • App-specific files, App preferences and Database are clearly not suitable as amongst other things these files do not survive an uninstall
  • Documents and other files uses the Storage Access Framework, but this is not suitable because it requires a system file picker every time you want to write something. This would disrupt the flow of recording/user experience, and no camera app works like that.
  • Datasets/BlobStoreManager (here) also is not appropriate for my use case.
  • MediaStore API looks like it should be the one, but it can't seem to do what I want in terms of producing a whole directory of outputs, including custom YAML/JSON/CSV text files, that all belong together. My aim is that the user at all times can simply go to the file explorer, navigate to the appropriate folder, and just copy out the folder(s) with the recordings to their computer or whatever, to save/view the data. Even MediaStore.Files does not seem to guarantee you can actually do that if your app is using scoped storage.

似乎剩下的唯一选择是使用MANAGE_EXTERNAL_STORAGE并将数据放置在主目录中的任意位置,但这似乎是一个极端的权限,要求它只是为了能够保存一些文本文件以及我制作的视频.此外,该权限是特定于Android 11的.如果我想支持较旧的Android版本,该怎么办?

The only option that seems to be left is using MANAGE_EXTERNAL_STORAGE and putting the data wherever I want in the home directory, but that seems like a bit of an extreme permission to be asking for just in order to be able to save some text files along with my produced videos. Also, that permission is Android 11 specific. If I want to support older Android versions, what would I need to do?

在这里我最好的选择是什么?有我错过的选择吗?

What is my best choice here? Is there an option I've missed?

推荐答案

但这不合适,因为每次您要写东西时都需要系统文件选择器

but this is not suitable because it requires a system file picker every time you want to write something

否.

使用 ACTION_OPEN_DOCUMENT_TREE 让用户选择文档树.在其中,您可以创建自己的子树并将自己的文档放入该子树中.您不需要系统文件选择器"超出初始 ACTION_OPEN_DOCUMENT_TREE 请求本身之外的任何内容.这样生成的文档将在卸载后幸存下来.

Use ACTION_OPEN_DOCUMENT_TREE to let the user pick a document tree. In there, you can create your own sub-tree and put your own documents into that sub-tree. You do not need the "system file picker" for anything beyond the initial ACTION_OPEN_DOCUMENT_TREE request itself. And the resulting documents will survive an uninstall.

这篇关于Android 11:如何/在何处写入应在卸载后仍然存在的混合媒体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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