Android4.x get (also monitor) external SD path and read/write

Source: Internet
Author: User

First:

      

This small demo is to determine whether the phone is inserted into the SD card (manually inserted into the case of the mobile card slot), if the SD card is unplugged, it will detect that there is no SD, will prompt to exit. You can modify the code to achieve your desired effect.

SD card loading status is obtained from the system files, "/system/etc/vold.fstab" and "/proc/mounts" (Detailed mount process can refer to this blog http://blog.csdn.net/yihongyuelan/ article/details/6963485).
However, there is a problem, 4.0 after the external SD read and write permissions into the system permissions, so if not the system application can not read and write external SD card. But when I get to the external SD card path, I find that I can read and write,
It is not known whether the setwritable (true) setting is the cause. What's wrong with everyone to communicate together.

What is an external SD card and a built-in SD card?

External: There is an extended SD card slot on the phone, the SD card inserted here is called an external SD card.
Built-in: is the phone's own SD, such as the current 16g, 32g mobile phones are built-in a 16g or 32g SD card.
Note: Some older mobile phones have a card slot but no built-in SD card, but the card slot is inserted as an internal SD card. (So I made a decision in the code: environment.isexternalstorageremovable () This method to determine whether the built-in SD card can be removed, can be removed to indicate that the phone has a card slot but no built-in SD card)

  Demo Download: Http://files.cnblogs.com/wangyuehome/testAndroid.zip

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.