Get internal and external memory cards in your phone

Source: Internet
Author: User

The internal and external memory card of the mobile phone introduction can refer to Blog: http://blog.sina.com.cn/s/blog_5da93c8f0102vcam.html

public class Mainactivity extends Activity {



@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.test_main_layout);
/** Device Manager */
StorageManager StorageManager = (StorageManager) getsystemservice (Context.storage_service);
try {
Class<?>[] paramclasses = {};
/** Reflection Implementation */
Method Getvolumepathsmethod = StorageManager.class.getMethod ("getvolumepaths", paramclasses);
Getvolumepathsmethod.setaccessible (TRUE);
Object[] params = {};
Object invoke = Getvolumepathsmethod.invoke (StorageManager, params);
for (int i = 0; I < ((string[]) invoke). Length; i++) {
/** Android.os under the Statfs class is mainly used to obtain the state of the file system, to obtain the size of the SD card and the remaining space, to obtain the system internal space is the size of the/system and the remaining space and so on. */
StatFs stat = Getstatfs (((string[]) invoke) [i]);
LOG.I ("LDM", ((string[)) invoke) [I] + ":" + CALCULATESIZEINMB (stat));
}
}
catch (Exception E1) {
E1.printstacktrace ();
}
}


Private StatFs Getstatfs (String path) {
try {
return new StatFs (path);
}
catch (Exception e) {
E.printstacktrace ();
}
return null;
}
/** calculate the available capacity of the memory card (in M) */
Private float CALCULATESIZEINMB (StatFs stat) {
if (stat! = null)
return Stat.getavailableblocks () * (Stat.getblocksize ()/(1024f * 1024f));
return 0.0f;
}
}

Get internal and external memory cards in your phone

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.