Last active
September 30, 2017 20:43
-
-
Save xalexchen/4276083 to your computer and use it in GitHub Desktop.
Android: Finding the SD Card Path “In devices with multiple ‘external’ storage directories (such as both secure app storage and mountable shared storage), this directory represents the ‘primary’ external storage that the user will interact with.” replace method Environment.getExternalStoreDirectory()
This file contains 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
File file = new File("/system/etc/vold.fstab"); | |
FileReader fr = null; | |
BufferedReader br = null; | |
try { | |
fr = new FileReader(file); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
try { | |
if (fr != null) { | |
br = new BufferedReader(fr); | |
String s = br.readLine(); | |
while (s != null) { | |
if (s.startsWith("dev_mount")) { | |
String[] tokens = s.split("\\s"); | |
path = tokens[2]; //mount_point | |
if (!Environment.getExternalStorageDirectory().getAbsolutePath().equals(path)) { | |
break; | |
} | |
} | |
s = br.readLine(); | |
} | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
if (fr != null) { | |
fr.close(); | |
} | |
if (br != null) { | |
br.close(); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment