Created
August 6, 2015 13:11
-
-
Save matan23/693674ab4f8d6e1de952 to your computer and use it in GitHub Desktop.
Check if true SDCard is mounted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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