我可以在 Android 内部存储上创建文件夹吗?

发布于 2024-11-30 23:51:23 字数 211 浏览 0 评论 0原文

假设我正在处理一个文本编辑器应用程序。我想将创建的文本文件存储在手机或 SD 卡中的文件夹中(由用户选择)。我只想将文件保存到内部存储(手机)上的文件夹中。我可以通过代码在 Android 内部存储上创建一个文件夹并将这些文件复制到那里吗?一个文件夹不会是我的应用程序私有的,也不会存储在“/data/data/MyapplicationPackage/”下,并且用户可以访问(读取)? 有什么提示吗?谢谢。

Assume I'm dealing with a text editor application. I want to store created text files on a folder which will be in the phone or sdcard (from user choice). I just want to save files onto a folder on internal storage(phone). Am i able to create a folder on android internal storage from code and copy these files there? A folder which will not be private to my application or store under "/data/data/MyapplicationPackage/" and witch from the user could access(read)?
Any hint? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

作妖 2024-12-07 23:51:23

为了满足您的要求,您可以:

  1. 将应用程序的文件和文件夹存储在外部存储(SD 卡)上。
  2. 提供某种“导出”功能,让用户导出其文件和文件夹(可能捆绑在 zip 文件中)。如果您使用ACTION_SEND,您可以让他们通过电子邮件发送导出的文件、保存到 Dropbox 等,几乎免费。
  3. 通过 ContentProvider 提供数据,以隐藏实际的存储机制。根据数据类型,您可能希望控制对该提供程序的访问。

To satisfy your requirement you can either:

  1. Have your app's files and folders stored on external storage (SD card).
  2. Provide some sort of 'export' feature letting users export their files and folders (possibly bundled in a zip file). If you use the ACTION_SEND you can let them send the exported files by email, save to Dropbox, etc. practically for free.
  3. Make your data available via a ContentProvider to hide the actual storage mechanism. Depending on the type of data, you might want to control access to that provider.
小鸟爱天空丶 2024-12-07 23:51:23

据我所知,可以,但不符合您的标准。
它将是私有的,存储在 /data/data/... 下,并且用户无法访问(除非通过应用程序)。除非用户已获得 root 权限。

As far as I know, you can, but it does not meet your criteria.
It will be private, stored under /data/data/..., and will not be user accessible except via the application. That is unless the user is rooted.

万劫不复 2024-12-07 23:51:23

请查看此处。您有很多选项可以做到这一点,所有这些都取决于您设备上安装的名称。请参阅 API getDir() 来为私有文件创建文件路径。

还要检查录音机应用程序正在写入其文件的路径,这为我解决了问题,因为由于缺乏许可,我无法让任何私人文件工作。

您始终可以在控制台模式下输入 ADB,使用“adb shell”并运行 linux“mount”命令来查看所有已安装的文件,但您需要 root 访问权限。

Take a look in here. You have many options to do that, and all depends on mounted names on your device. See APIs getDir() to create a filepath for a private file.

Check also in which path the audio recorder application is writing its files, that solved for me since I could'nt get any private file working for lack of permitions.

You can always enter ADB in console mode, with "adb shell" and run a linux "mount" command to see all your mounted files, you'll need root access though.

感情旳空白 2024-12-07 23:51:23

我也面临着同样的问题。我想在内存中创建一个文件夹。我尝试了 stackoverflow 本身提供的许多代码。但这些都不能正常工作。所以最后我给了我自己的根目录。

File newFolder = new File("/storage/emulated/0/", "Folder_Name");

这段代码对我来说工作得非常好。

I also was facing same problem. I wanted to create a folder in Internal Memory. I tried many code provided in stackoverflow itself. But non of those worked properly. So at last I gave the root directory own my own.

File newFolder = new File("/storage/emulated/0/", "Folder_Name");

This code worked absolutely fine for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文