Android infers if SD card exists and capacity query

Source: Internet
Author: User

First to join the permissions <uses-permission android:name = "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/><uses-permission Android:name= "Android.permission.WRITE_EXTERNAL_STIRAGE"/>


Infer if the SD card exists

/* * Infer if the SD card exists */private Boolean exitsdcard () {if (Environment.getexternalstoragestate (). Equals ( Android.os.Environment.MEDIA_UNMOUNTED) {return true;} else {return false;}}

<span style= "White-space:pre" ></span>/* * View SD card Total capacity */@SuppressWarnings ("deprecation") public long Getsdallsize () {String path = Environment.getexternalstoragedirectory (). GetPath (); StatFs SF = new StatFs (path), int blockSize = Sf.getblocksize (); int allblocks = Sf.getblockcount (); return (Allblocks * bloc ksize)/1024/1024;}
/* *  View the remaining space on the SD card */@SuppressWarnings ("deprecation") public long Getsdfreesize () {String path = Environment.getexternalstoragedirectory (). GetPath (); StatFs StatFs = new StatFs (path), int size = Statfs.getblocksize (); int freeblocks = Statfs.getavailableblocks (); Return (FR Eeblocks * size)/1024/1024;}



Android infers if SD card exists and capacity query

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.