简体   繁体   English

将文件写入外部SDCard -android

[英]Writing files to external SDCard -android

我一直在尝试将应用程序中的文件写入外部sdcard,但未写入文件,我的测试手机是Galaxy Duos和LG,当我在LG手机上尝试时,它可以正常工作,但是LG手机具有android版本是4.1.2。而星系是4.4.2,我想这与kitkat 4.4中SDCard的变化有关,想知道是否有人可以解决它?

In 4.4 the application can not write data to any place on the external SD card. 在4.4中,应用程序无法将数据写入外部SD卡上的任何位置。 The application can write the data only to certain folders on the external card (under /extSdCard/Android/data/ path). 该应用程序只能将数据写入外部卡上的某些文件夹(在/ extSdCard / Android / data /路径下)。 This is a new restriction imposed by Google that is supposed to allow users to delete all data associated to the application after the application is uninstalled. 这是Google施加的一项新限制,旨在允许用户在卸载应用程序后删除与该应用程序关联的所有数据。

Here's the detailed explanation . 这是详细的说明

With Android 4.4 (KitKat), Google blocked apps from writing to the SD card except for a very specific sandboxed location. 使用Android 4.4(KitKat),Google阻止了应用程序写入SD卡的操作,除了特定的沙盒位置。 Apps have direct write access ONLY to their package-specific directories as obtained through Context.getExternalFilesDirs(), Context.getExternalCacheDirs(), etc. "Direct" access is defined as using traditional file access APIs, like POSIX open(). 应用程序只能访问自己的包特定的目录,通过Context.getExternalFilesDirs(获得)直接写访问,Context.getExternalCacheDirs()等“直接”访问被打开定义为使用传统文件访问API,像POSIX()。 Direct access to the remainder of these secondary external storage devices remains read-only for apps. 对于应用程序,直接访问这些辅助外部存储设备的其余部分仍然是只读的。

However, apps can create/write files outside of their package-specific directories on secondary external storage devices by using the new CREATE_DOCUMENT intent, which involves the user in the file creation process. 但是,应用程序可以使用新的CREATE_DOCUMENT意图在辅助外部存储设备上的特定于程序包的目录之外创建/写入文件,这将使用户参与文件创建过程。

Notably, Google's Nexus devices do not include micro SD card support; 值得注意的是,Google的Nexus设备不支持micro SD卡; however, many other Android-powered devices do feature micro SD card functionality. 但是,许多其他基于Android的设备的确具有Micro SD卡功能。 The previous version of Android left devices vulnerable from a security standpoint, but Google has now addressed these safety concerns by limiting what third-party apps can do with a Micro SD card. 从安全角度来看,以前的Android版本使设备容易受到攻击,但是Google现在通过限制第三方应用程序可以使用Micro SD卡来解决这些安全问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM