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