有没有办法识别一个设备中是否有两个SD卡??
编辑:
我发现目前还没有办法区分内部存储和真正的外部SD卡。在某些设备中,如三星Galaxy Tab (7英寸),系统将内部存储(通常为16 as )作为外部存储。不幸的是,没有办法区分内部存储和辅助/外部/SD卡存储。如果有人认为这是可能的(对于蜂巢和以前的版本),写在这里,我会证明这一点。
发布于 2011-08-13 02:26:47
我不相信有一种方法可以检查双sd卡,但一些设备确实有两种类型的外部存储。例如,我知道在摩托罗拉的一些设备上,内部二级存储是通过/sdcard-ext访问的。您可以检查此目录是否存在(我知道具有辅助存储的其他设备也使用-ext追加),并做出相应的反应。
发布于 2013-09-18 15:17:23
有些设备同时具有模拟SD和物理SD。(例如Sony Xperia Z)。它不会公开物理SD卡,因为像getExternalFilesDir(null)这样的方法将返回模拟的SD卡。我使用以下代码来获取物理SD的目录。该调用返回所有挂载点和在线SD卡。您必须找出哪个挂载点是指离线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);
}https://stackoverflow.com/questions/7044545
复制相似问题