Android SDcard Information acquisition

Source: Internet
Author: User

There are two types of mobile phone storage, one is the storage of the handset, called internal storage, another kind of user's extra storage, called Removable Storage (that is, the part of the external sdcard).

The path of Removable Storage is generally storage/emulated/0/android/data/com.example.storagetest/files/alarm

Internal storage also has a part called external (that is, the part of the built-in sdcard), and this part of the path is/storage/emulated/0

Get the built-in SDcard path method

by Context.get....dir or Environment.get...dir to get

Get the external SDcard path method

1.String Extsdcardpath = system.getenv ("Secondary_storage");

2. Get through StorageManager.

StorageManagerMstoragemanager=(StorageManager)Mcontext.Getsystemservice(Context.Storage_service);Class<?>Storagevolumeclazz=Null;Try{Storagevolumeclazz=Class.Forname("Android.os.storage.StorageVolume");MethodGetvolumelist=Mstoragemanager.GetClass().GetMethod("Getvolumelist");MethodGetPath=Storagevolumeclazz.GetMethod("GetPath");MethodIsRemovable=Storagevolumeclazz.GetMethod("IsRemovable");ObjectResult=Getvolumelist.Invoke(Mstoragemanager);FinalIntLength=Array.GetLength(Result);For(IntI=0;I<Length;I++){ObjectStoragevolumeelement=Array.Get(Result,I);StringPath=(String)GetPath.Invoke(Storagevolumeelement)//If there is an external sdcard, then the Sdcard1 is external.BooleanRemovable=(Boolean)IsRemovable.Invoke(Storagevolumeelement);If(Is_removale==Removable){ReturnPath;}}}Catch(ClassNotFoundExceptionE){E.Printstacktrace();}Catch (invocationtargetexception e{ span class= "n" >e. (); } catch  (nosuchmethodexception e< Span class= "O" >) {e. Printstacktrace (); } catch  (illegalaccessexception e ) {e. Printstacktrace ();  return null       

Android SDcard Information acquisition

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.