Android to determine if SD card exists and capacity

Source: Internet
Author: User

First, add the SD card access to the Androidmanifest.xml

<!---  <android:name = " Android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/>  <!----   <android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"  />   
    //whether the SD exists    Private BooleanExistsdcard () {if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {return true; } Else                 return false; }    //SD remaining space     Public Longgetsdfreesize () {//get SD card file pathFile Path =environment.getexternalstoragedirectory (); StatFs SF=NewStatFs (Path.getpath ()); //gets the size of a single data block (Byte)         LongBlockSize =sf.getblocksize (); //the number of free data blocks         LongFreeblocks =sf.getavailableblocks (); //return SD card idle size//return freeblocks * blockSize; //Unit byte//return (Freeblocks * blockSize)/1024; //Unit KB         return(Freeblocks * blockSize)/1024/1024;//units MB    }    //SD Total Capacity     Public Longgetsdallsize () {//get SD card file pathFile Path =environment.getexternalstoragedirectory (); StatFs SF=NewStatFs (Path.getpath ()); //gets the size of a single data block (Byte)        LongBlockSize =sf.getblocksize (); //get the number of all data blocks        LongAllblocks =Sf.getblockcount (); //return SD card size//return allblocks * blockSize;//Unit byte//return (allblocks * blockSize)/1024;//Unit KB        return(Allblocks * blockSize)/1024/1024;//units MB}

Android to determine if SD card exists and capacity

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.