The method of obtaining SDcard card information by Android programming _android

Source: Internet
Author: User

The example in this article describes how Android programming obtains SDcard card information. Share to everyone for your reference, specific as follows:

public static Sdcardinfo Getsdcardinfo () {String sdcstring = Android.os.Environment.getExternalStorageState (); if (Sdcstring.equals (Android.os.Environment.MEDIA_MOUNTED)) {File Pathfile =
   Android.os.Environment.getExternalStorageDirectory ();
    try {android.os.StatFs statfs = new Android.os.StatFs (Pathfile.getpath ());
    Gets the total number of blocks on the sdcard long ntotalblocks = Statfs.getblockcount ();
    Gets the size long nblocsize = Statfs.getblocksize () of each block on the sdcard;
    Gets the number of blocks that can be used by the program long Navailablock = Statfs.getavailableblocks ();
    Gets the number of all remaining blocks (including chunks that are not used by the reserved general program) long Nfreeblock = Statfs.getfreeblocks ();
    Sdcardinfo info = new Sdcardinfo ();
    Calculates sdcard Total capacity MB Info.total = Ntotalblocks * nblocsize;
    Calculates sdcard remaining size MB Info.free = Navailablock * nblocsize;
   return info;
   catch (IllegalArgumentException e) {log.e (Log_tag, e.tostring ());
} return null;
} sdcardinfo Sdcardinfo = Util.getsdcardinfo (); SD Card Total Capacity SdcardinFo.total//SD card remaining capacity Sdcardinfo.free

 

I hope this article will help you with your Android programming.

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.