1. Write the data to the SDcard:
Found to write data to the/mnt/sdcard path error, cause: The appropriate permissions are not turned on
FIX: Add in config file
<android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Or:
In addition: Do not recommend hard-coded written:/mnt/sdcard, should be written like this:
String Sdpath = Environment.getexternalstoragedirectory (). GetPath ();
Before you save the data to SDcard, you should also determine if there is a sdcard:
if (Environment.MEDIA_MOUNTED.equals (Environment . Getexternalstoragestate ())) { = Environment.getexternalstoragedirectory () . GetPath (); // ...... Else { "SD card is not available", Toast.length_long). Show (); }
2. Get sdcard total size and free space:
File File = environment.getexternalstoragedirectory (); // Total size long totalspace = file.gettotalspace (); // Available Sizes long usablespace = file.getusablespace (); // Note The return format is byte, and the conversion String formattotalspace = Formatter.formatfilesize (mainactivity. this, totalspace); = Formatter.formatfilesize (mainactivity. this, usablespace);
Android Development: SD card operation