About the phone's built-in SD card and external SD card

Source: Internet
Author: User

for Android2.3 of systems,environment.getexternalstoragedirectory () Get the directory is built-in SD card or external SD card is not guaranteed, and the handset manufacturer's modification, Can only be judged by environment.isexternalstorageremovable ().,If True is external, because external can be uninstalled. (But I've only met Android at the moment. )The 4.4 system has a built-in SD card, soenvironment.getexternalstoragedirectory ()in the 2.3 system for external use, encountered special models and then consider other methods)

For Android 4.0 and above the system is good to do, you can use reflection to achieve the distinction between internal and external SD card, the code is as follows:

1StorageManager StorageManager =(StorageManager) Getsystemservice (context.storage_service);2         Try {3String [] strings = (string[]) Storagemanager.getclass (). GetMethod ("Getvolumepaths"). Invoke (StorageManager);4              for(inti = 0; i < strings.length; i++) {5 System.out.println (Strings[i]);6             }7}Catch(Exception e) {8 e.printstacktrace ();9}

And then call:

1 environment.getexternalstoragedirectory (); // get an SD card path 2 environment.isexternalstorageremovable (); // determine if the SD card is uninstalled

Next you will Environment.getexternalstoragedirectory (): ToString () Gets the string from the strings[i] inside the comparison, you can distinguish which is the built-in which is external.

&NBSP;

About the phone's built-in SD card and external SD card

Related Article

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.