public class Mainactivity extends Appcompatactivity {
String TAG = MainActivity.class.getCanonicalName ();
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
String storagestate = Environment.getexternalstoragestate ();
Status of SD card
LOG.E (TAG, "onCreate:" +storagestate);
LOG.E (TAG, "onCreate:" +environment.media_mounted);
Determine if there is an SD card
Boolean equals = Environment.MEDIA_MOUNTED.equals (Environment.getexternalstoragestate ());
LOG.E (TAG, "onCreate:" +equals);
Get the path to the SD card
String Absolutepath = Environment.getexternalstoragedirectory (). GetAbsolutePath ();
LOG.E (TAG, "onCreate:" +absolutepath);
Get all the files in the built-in SD card
File File = Environment.getexternalstoragedirectory ();
file[] files = file.listfiles ();
for (int i = 0; i < files.length; i++) {
LOG.E (TAG, "onCreate:" +files[i]);
}
Long freeSpace = Environment.getexternalstoragedirectory (). Getfreespace ();
Long usablespace = Environment.getexternalstoragedirectory (). Getusablespace ();
Long totalspace = Environment.getexternalstoragedirectory (). Gettotalspace ();
LOG.E (TAG, "onCreate: Remaining space size:" +freespace/1024/1024+ "Available size:" +usablespace/1024/1024+ "Total space size:" +totalspace/1024/1024);
}
}
Demo:https://github.com/renjiemei1225/extratest
Android to determine the status of SD, all files, the size of the remaining space