Android4. 4. Detailed explanation and examples of accessing external storage

Android4. 4 access to external storage

In the Android 4.4 system, the external memory card (SD card) is called secondary storage, and the application cannot write data to the external memory card (SD card), and write_ EXTERNAL_ Storage only grants write permission to the primary storage on the device. For other external storage, the file attributes on it are changed to be based on the folder structure, and the application does not need to obtain write_ EXTERNAL_ Storage permission, but you can manage folders related to your package name. For example, if the package name of the application is com example. External storage, then Android / data / COM on external storage example. The external storage / folder is its. It can be accessed at will without permission. In addition, it should be noted that when the application is uninstalled, the corresponding folders and data created on the SD card will be completely deleted at the same time.

The exception is that in Android 4.4, system applications (those with platform signature or pre installed in / system / priv app directory) can use write_ MEDIA_ The storage permission obtains the permission to fully read and write the SD card.

Android 4.4 adds the following functions to access external storage:

Context. Getexternalfilesdirs (null) returns the files directory of the application private data area of multiple SD cards

/Storage / sdcard0 / Android / data / < package name > / files

/Storage / sdcard1 / Android / data / < package name > / files

Context. Getexternalcachedir(), returns the cache directory of the application private database under multiple SD cards

/Storage / sdcard0 / Android / data / < package name > / caches

/Storage / sdcard1 / Android / data / < package name > / caches

Context. Getobbdirs(), return the private data under the OBB directory of multiple SD cards (this directory is generally the packet directory of the game)

/Storage / sdcard0 / Android / OBB / < package name >

/Storage / sdcard1 / Android / OBB / < package name >

Through the above function, I can correctly obtain the SD card path on my android 5.1 system, but in Android 4.0 4. Only internal storage paths can be seen on the system.

According to the information on the Internet, after Android 4.4, you can manage SD cards by modifying system files as follows:

Modify / system / etc / permissions / platform Android. XML file permission. WRITE_ EXTERNAL_ Storage node, add < group GID = "media_rw" / > (root permission is required).

After modification, the application can control the SD card at will.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>