Skip to content

Instantly share code, notes, and snippets.

@matan23
Created August 6, 2015 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matan23/693674ab4f8d6e1de952 to your computer and use it in GitHub Desktop.
Save matan23/693674ab4f8d6e1de952 to your computer and use it in GitHub Desktop.
Check if true SDCard is mounted
String strSDCardPath = System.getenv("SECONDARY_STORAGE");
if ((null == strSDCardPath) || (strSDCardPath.length() == 0)) {
strSDCardPath = System.getenv("EXTERNAL_SDCARD_STORAGE");
}
try {
// Open the file
FileInputStream fs = new FileInputStream("/proc/mounts");
DataInputStream in = new DataInputStream(fs);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
StringBuilder sb = new StringBuilder();
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Remember each line
sb.append(strLine);
}
String s = sb.toString();
if (s.contains(strSDCardPath)) {
Log.d("BLA", "MOUNTED!!");
} else {
Log.d("BLA", "NOT MOUNTED");
}
//Close the stream
in.close();
} catch (Exception e) {
//Catch exception if any
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment