Android Development to obtain SD card and cell phone ROM capacity method _android

Source: Internet
Author: User

This article is an example of how Android obtains SD card and cell phone ROM capacity. Share to everyone for your reference, specific as follows:

Here is a simple example to get the capacity of the SD card and the capacity of the cell phone ROM, the code is as follows:

Package com.urovo.sdcardspace;
Import Java.io.File;
Import Android.os.Bundle;
Import android.os.Environment;
Import Android.os.StatFs;
Import android.app.Activity;
Import Android.text.format.Formatter;
Import Android.view.Menu;
Import Android.widget.TextView; public class Mainactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {super.
    OnCreate (savedinstancestate);
    Setcontentview (R.layout.activity_main);
    TextView TV = (TextView) Findviewbyid (r.id.tv); File path = Environment.getexternalstoragedirectory ();//Get SD card path statfs stat = new Statfs (Path.getpath ());//Create Statfs Object
    , used to get the state of the file system long Blockcount = Stat.getblockcount ();
    Long blockSize = Stat.getblocksize ();
    Long availableblocks = Stat.getavailableblocks (); String totalsize = Formatter.formatfilesize (Getapplicationcontext (), blockcount*blocksize);//Format get SD card Total capacity String availablesize = Formatter.formatfilesize (Getapplicationcontext (), blockcount*availableblocks)//obtain SD card usable capacity Tv.settext ("SD card Total Capacity:" +totalsize+ "\NSD card usable Capacity:" +availablesize+ "\ n" +getromspace ());
    Private String Getromspace () {File path = Environment.getdatadirectory ();
    Statfs stat = new Statfs (Path.getpath ());
    Long Blockcount = Stat.getblockcount ();
    Long blockSize = Stat.getblocksize ();
    Long availableblocks = Stat.getavailableblocks ();
    String totalsize = formatter.formatfilesize (Getapplicationcontext (), blockcount*blocksize);
    String availablesize = formatter.formatfilesize (Getapplicationcontext (), blockcount*availableblocks);
  Return "Mobile ROM Total capacity:" +totalsize+ "\ Phone rom usable capacity:" +availablesize;

 }
}

Specific content, you can analyze the Android settings part of the source code, to deepen understanding.

For more information on Android-related content readers can view the site: "Android programming development of the SD card operation method Summary", "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android View tips Summary" and "The Android Control usage Summary"

I hope this article will help you with the Android program.

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.