아래는 sd 카드 디렉토리를 검색하기 위해 작성된 코드입니다. 명령 실행을 사용하고/proc/mounts를 읽는 것으로 변경되었습니다. 내 질문은 올바른 코드인지 여부입니다.안드로이드 장치의 SD 카드 디렉토리 받기
Linux OS에 익숙하지 않습니다./proc/mounts 경로가 모든 장치에서 동일합니까? 이 코드는 명령 주입 가능성이 없다고 생각합니다.
// Process process = new ProcessBuilder().command("mount").start();
// process.waitFor();
reader = new BufferedReader(new FileReader("/proc/mounts"));
String line;
while ((line = reader.readLine()) != null) {
// Output the line of output from the mount command
logger.debug(" {}", line);
if (line.startsWith("/dev/block/vold/")) {
String[] tokens = line.split(" ");
if (tokens.length >= 3 && (tokens[2].equals("vfat") || tokens[2].equals("exfat"))) {
String path = tokens[1];
File file = new File(path);
if (file.exists() && file.isDirectory()) {
logger.debug("Detected SD card at {}", file.getPath());
if (!file.canWrite()) {
logger.warn("The SD card path {} is reporting that it is not writable", file.getPath());
}
return path;
}
}
}
}
환호, Saurav 안드로이드에
순전히) (안드로이드 sdcard에 경로 –
Environment.getExternalStorageDirectory을 얻기 위해 할 수있는 y를 읽을 경우
또한, 확인하는 속성
Environment.MEDIA_MOUNTED
등에 대해Environment.getExternalStorageState()
를 사용; –다른 API는 외부 저장소를 다르게 고려할 것이므로이 API를 사용하는 것이 정확하지 않을 것입니다.이 http://stackoverflow.com/questions/9340332/how-can-i-get-the-list-of를 확인하십시오. -mounted-external-storage-of-android-device/19982338 # 19982338 – saurav