Android to determine if there is an SD card in the phone, USB. static judgment

Source: Internet
Author: User

    public static string Getsdpath (context context) {        string sd = null;        StorageManager StorageManager = (storagemanager) context                . Getsystemservice (context.storage_service);        storagevolume[] volumes = Storagemanager.getvolumelist ();        for (int i = 0; i < volumes.length; i++) {            if (volumes[i].isremovable () && volumes[i].allowmassstorage () 
   && volumes[i].getdescription (context). Contains ("SD")) {                SD = Volumes[i].getpath ();            }        }        return SD;    }
The SD card to determine the static and dynamic, dynamic through the registration of radio, many people on the Internet are writing, here do not do too much elaboration. For this kind of static judgment, I look for it on the Internet.
<span style= "Color:rgb (51, 51, 51); Font-family: Song body; font-size:14px; line-height:28px; text-indent:28px; " > environment.getexternalstoragestate (). Equals (</span><span style= "Color:rgb (Wuyi, Wuyi, Wuyi); font-family: Song body; font-size:14px; line-height:28px; text-indent:28px; " >environment.media_mounted); After writing code verification, it is found that the judgment is unsuccessful. </span>
<span style= "Color:rgb (51, 51, 51); Font-family: Song body; font-size:14px; line-height:28px; text-indent:28px; " ></span>
<span style= "Color:rgb (51, 51, 51); Font-family: Song body; font-size:14px; line-height:28px; text-indent:28px; " > Below is the determination of USB. </span>
<span style= "Color:rgb (51, 51, 51); Font-family: Song body; font-size:14px; line-height:28px; text-indent:28px; " ><span style= "White-space:pre" ></span></span><pre name= "code" class= "Java" > Public        Static Boolean Usbexist (Context context) {Boolean ret = false;        StorageManager StorageManager = (storagemanager) context. Getsystemservice (Context.storage_service);            if (StorageManager = = null) {LOG.E (TAG, "Invalid reference to StorageManager received.");        return ret; } try {if (Storagemanager.getvolumestate (Getusbpath). Equals (ANDROID.OS.ENV Ironment.            media_mounted)) {ret = true;        }} catch (Exception e) {log.e (TAG, e.tostring ());    } return ret;        public static string Getusbpath (context context) {string USB = null;            StorageManager StorageManager = (StorageManager) context    . Getsystemservice (Context.storage_service);        storagevolume[] volumes = Storagemanager.getvolumelist (); for (int i = 0; i < volumes.length; i++) {if (volumes[i].isremovable () && Volumes[i].allowmassstora GE () && volumes[i].getdescription (context). Contains ("USB") {USB = VOLUMES[I].G            Etpath ();    }} return USB; }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android to determine if there is an SD card in the phone, USB. static judgment

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.