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