Android4.4 access to external storage and examples _android

Source: Internet
Author: User

Android4.4 access to external storage

In the Android 4.4 system, an external storage card (SD card) is called a level two external storage device (secondary storage), and the application is unable to write data to an external memory card (SD card) and Write_external_ Storage grants write access only to the primary external store on the device (primary storage), and for other external storage, the file attributes on the folder structure are changed, and the application does not need to obtain Write_external_storage permissions. However, you can manage the folders associated with your own package name. For example, if the application's package name is Com.example.externalstorage, then the android/data/com.example.externalstorage/folder on the external store is it, accessible without permission. Another special note is that when the application is uninstalled, the corresponding folders and data created on the SD card are completely deleted at the same time.

The exception is that in Android 4.4, the System application (refers to the platform signature, or pre-installed in the/system/priv-app directory application) can be used to obtain full access to the SD card by using Write_media_storage permissions.

Android 4.4 Adds the following function to access external storage:

Context.getexternalfilesdirs (NULL), returns the files directory of the application private data area for multiple SD cards

/storage/sdcard0/android/data/< Package Name >/files

/storage/sdcard1/android/data/< Package Name >/files

Context.getexternalcachedirs (), returns the cached 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 (), returns private data in the OBB directory under multiple SD cards (this directory is typically the game's packet directory)

/storage/sdcard0/android/obb/< Package Name >

/storage/sdcard1/android/obb/< Package Name >

The above function can get the SD card path correctly on my Android 5.1 system, but only the internal storage path is visible on the Android4.4 system.



According to the information on the Internet, Android 4.4 can later manage the SD card by modifying the system files, as follows:

1<permission name= "Android.permission.WRITE_EXTERNAL_STORAGE" >
2     <group gid= "Sdcard_r"/>
3     <group gid= "SDCARD_RW"/>
4     <group gid= "MEDIA_RW"/>
5   </permission>

Modify the Android.permission.WRITE_EXTERNAL_STORAGE node of the/system/etc/permissions/platform.xml file to add <group gid= "MEDIA_RW" /> (requires root permission).

After the modified application can be arbitrary control SD card.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.