에뮬레이트 된 SD와 물리적 인 SD가 모두있는 장치가 있습니다. (예 : Sony Xperia Z). getExternalFilesDir (null)과 같은 메서드는 에뮬레이트 된 SD 카드를 반환하기 때문에 실제 SD 카드를 노출하지 않습니다. 다음 코드를 사용하여 실제 SD에 대한 디렉토리를 가져옵니다. 이 호출은 모든 마운트 포인트와 온라인 SD 카드를 반환합니다. 어떤 마운트 지점이 OFFLINE SD 카드 (있는 경우)를 가리키는 지 파악해야하지만 대부분의 경우 온라인 SD 카드에만 관심이 있습니다.
public static boolean getMountPointsAndOnlineSDCardDirectories(ArrayList<String> mountPoints, ArrayList<String> sdCardsOnline)
{
boolean ok = true;
mountPoints.clear();
sdCardsOnline.clear();
try
{
// File that contains the filesystems to be mounted at system startup
FileInputStream fs = new FileInputStream("/etc/vold.fstab");
DataInputStream in = new DataInputStream(fs);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = br.readLine()) != null)
{
// Skip comments and empty lines
line = line.trim();
if ((line.length() == 0) || (line.startsWith("#"))) continue;
// Fields are separated by whitespace
String[] parts = line.split("\\s+");
if (parts.length >= 3)
{
// Add mountpoint
mountPoints.add(parts[2]);
}
}
in.close();
}
catch (Exception e)
{
ok = false;
e.printStackTrace();
}
try
{
// Pseudo file that holds the CURRENTLY mounted filesystems
FileInputStream fs = new FileInputStream("//proc/mounts");
DataInputStream in = new DataInputStream(fs);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = br.readLine()) != null)
{
// A sdcard would typically contain these...
if (line.toLowerCase().contains("dirsync") && line.toLowerCase().contains("fmask"))
{
String[] parts = line.split("\\s+");
sdCardsOnline.add(parts[1]);
}
}
//Close the stream
in.close();
}
catch (Exception e)
{
e.printStackTrace();
ok = false;
}
return (ok);
}
예, 그렇습니다. 내부 저장 장치를 SD 카드로 간주하는 특정 장치가 있습니다. sd 카드로 취급되는 내부 저장 장치와 실제 외부 sd 카드를 구별 할 수있는 방법을 자세히 설명 할 수 있습니까? – Farhan
'Environment.isExternalStorageEmulated()'및'Environment.isExternalStorageRemovable()'을 살펴보십시오 - http://developer.android.com/reference/android/os/Environment.html을 참조하십시오. –