Titanium - Android 外部存储 - 创建新目录,然后将文件写入其中 [英] Titanium - Android external storage - create new directory and then write files into it

查看:18
本文介绍了Titanium - Android 外部存储 - 创建新目录,然后将文件写入其中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们不能简单地在 Android 的外部 SD 卡(不是设备的内部存储器)上以编程方式创建新目录,我们不能在 SD 卡上写入文件吗?

Can we not simply create new directory programmatically on external SD card (not internal memory of device) in Android and can we not write files on SD card?

即使在使用 Ti.Filesystem.externalStorageDirectory 之后,Titanium 是否也仅限于在内部存储器上写入文件?

Is Titanium so restricted to always write files on internal memory even after using Ti.Filesystem.externalStorageDirectory?

曾经能够在 Android 中的 SD 卡上以编程方式创建新目录的人能否在这里写下答案,或者没有人需要在外部 SD 卡上写一些东西?

Can someone who has ever been able to create a new directory programmatically on SD card in Android write the answer here or no one ever needs to write something on external SD card?

推荐答案

您可以使用 System 类来获取如下所示的存储变量

You can use System class to get storage variables like below

要获取您可以使用的内部 SD 卡

String extStore = System.getenv("EXTERNAL_STORAGE");
File f_exts = new File(extStore);

要获取可以使用的外部 SD 卡

String secStore = System.getenv("SECONDARY_STORAGE");
File f_secs = new File(secStore);

您可以选择在何处创建文件夹以及使用哪个文件夹.

You can choose where to create folder and which one to use.

编辑

  • 返回主共享/外部存储目录.
  • 如果该目录已被用户安装到其计算机上、已从设备中删除或发生了其他一些问题,则当前可能无法访问该目录.您可以使用 getExternalStorageState() 确定其当前状态.

注意:不要被这里的外部"一词所迷惑.这个目录最好被认为是媒体/共享存储.它是一个文件系统,可以保存相对大量的数据,并在所有应用程序之间共享(不强制执行权限).传统上,这是一张 SD 卡,但它也可以作为设备中的内置存储实现,与受保护的内部存储不同,可以作为文件系统安装在计算机上.

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

参考来自环境

希望它会有所帮助.

这篇关于Titanium - Android 外部存储 - 创建新目录,然后将文件写入其中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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