Android to determine if SD card exists and use capacity query

Source: Internet
Author: User

1. Determine if the SD card exists returns TRUE indicates that there is

1     /*determine if the SD card exists returns TRUE indicates that there is*/2      Public BooleanAvaiablemedia () {3String status =environment.getexternalstoragestate ();4 5         if(Status.equals (environment.media_mounted)) {6             return true;7}Else {8             return false;9         }Ten}

2. Get the SD card free space

1 /*get SD card free space*/2      Public Longgetsdfreesize () {3         //get SD card file path4File Path =environment.getexternalstoragedirectory ();5StatFs SF =NewStatFs (Path.getpath ());6         //gets the size of a single data block (Byte)7         LongBlockSize =Sf.getblocksizelong ();8         //the number of free data blocks9         LongFreeblocks =Sf.getavailableblockslong ();Ten         //return SD card idle size One         //return freeblocks * blockSize;//Unit byte A         //return (freeblocks * blockSize)/1024;//Unit KB -         return(Freeblocks * blockSize)/1024/1024;//units MB -}

3. Get all the space on the SD card

1 /*get all the space on your SD card*/2      Public Longgetsdallsize () {3         //get SD card file path4File Path =environment.getexternalstoragedirectory ();5StatFs SF =NewStatFs (Path.getpath ());6         //gets the size of a single data block (Byte)7         LongBlockSize =Sf.getblocksizelong ();8         //get the number of all data blocks9         LongAllblocks =Sf.getblockcountlong ();Ten         //return SD card size One         //return allblocks * blockSize;//Unit byte A         //return (allblocks * blockSize)/1024;//Unit KB -         return(Allblocks * blockSize)/1024/1024;//units MB -}

Android to determine if SD card exists and use capacity query

Related Article

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.