Operation of the Android SD card

Source: Internet
Author: User

/** * Get common path */public void Getdir () {///mnt/sdcardfile root=environment.getexternalstoragedirectory ();///systemFile Root=environment.getrootdirectory ();///cachefile root=environment.getdownloadcachedirectory ();///dataFile root= Environment.getdatadirectory ();///storage/emulated/0/music//string type=environment.directory_music;//string Type=environment.directory_pictures; File root=environment.getexternalstoragepublicdirectory (type); System.out.println ("root=" +root.getabsolutepath ());} /** * Get the total capacity of the phone SDcard * @return */public long getsdcardtotalcapacity () {if (This.issdcarduse ()) {///mnt/sdcardfile root= Environment.getexternalstoragedirectory ();//Get state File System Object StatFs statfs=new StatFs (Root.getpath ()) according to SDcard path;// Get the size of each piece of data, in bytes long blocksize=statfs.getblocksize (); System.out.println ("blocksize=" +blocksize);//Get the current phone sdcard altogether how many blocks of data long blockcount=statfs.getblockcount (); System.out.println ("blockcount=" +blockcount);//return blockcount*blocksize;//default in bytes return blockcount*blocksize /1024/1024/1024;//Default in bytes, converted to Gb}else{throw new RuntimeException ("Current phone sdcard does not exist or is not available!") ");}} /** * Get mobile sdcard usable capacity * @return */public long getsdcardavailablecapacity () {if (This.issdcarduse ()) {///mnt/sdcardfile Root=environment.getexternalstoragedirectory ();//SDcard The state file system object according to the path of the StatFs statfs=new statFs ( Root.getabsolutepath ());//Get the size of each piece of data, in bytes int blocksize=statfs.getblocksize ();//Get the current phone sdcard usable capacity of SDcard block number int Availableblocks=statfs.getavailableblocks ();//return availableblocks*blocksize;//default in bytes return availableBlocks* blocksize/1024/1024/1024;//Default in bytes, converted to Gb}else{throw new RuntimeException ("Current phone sdcard does not exist or is not available!") ");}} /** * Get phone sdcard remaining capacity * @return */public long getsdcardfreecapacity () {if (This.issdcarduse ()) {///mnt/sdcardfile root= Environment.getexternalstoragedirectory ();//Get state File System Object StatFs statfs=new StatFs (Root.getabsolutepath () according to SDcard Path );//Get the size of each piece of data, in bytes int blocksize=statfs.getblocksize ();//Get the current cell phone sdcard usable capacity sdcard block number int freeblocks= Statfs.getfreeblocks ();//return freeblocks*blocksize;//default in bytes reTurn freeblocks*blocksize/1024/1024/1024;//Default in bytes, converted to Mb}else{throw new RuntimeException ("Current phone sdcard does not exist or is not available!") ");}}}

  

Operation of the Android SD card

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.