As I know, there are 3 kinds of storage,
File internalFile = new File(getFilesDir(), "MyFile.txt");
File externalFile = new File(Environment.getExternalStorageDirectory(), "MyFile.txt");
My question is for third type of storage. How can I access to secondary SD card? I have searched for hours but I did not find the answer.
There are only 2 types,
Check this guide for more details. I hope it has all that you need.
You can detect the storage state, as specified in the guide, using the following code
/* Checks if external storage is available for read and write */ public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } /* Checks if external storage is available to at least read */ public boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; }
To detect sd card availability you can do it on this way
boolean mExtStorage = false;
boolean mExtWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mExtStorage = mExtWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
mExtStorage = true;
mExtWriteable = false;
} else {
mExtStorage = mExtWriteable = false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.