获取外置卡路径

public String getExtralCardPath()
{
try
{
FileReader fr = new FileReader("/system/etc/vold.fstab");
BufferedReader br = new BufferedReader(fr);
while (br.ready())
{
String line = br.readLine().trim();
if(line.startsWith("dev_mount"))
{
String[] arrStr = line.split(" ");
if(arrStr.length >= 5 && arrStr[0].equals("dev_mount")
&& arrStr[1].equals("sdcard"))
{
br.close();
if(new File(arrStr[2]).exists())
{
File f = new File(arrStr[2]);
if(f.canWrite())
{
return arrStr[2];
}
}
}
}
}
} catch (Exception e)
{
String path = "";
Map<String, String> map = System.getenv();
if(map.containsKey("SECONDARY_STORAGE"))
{
path = map.get("SECONDARY_STORAGE").split(":")[0];
} else if(map.containsKey("EXTERNAL_STORAGE"))
{
path = map.get("EXTERNAL_STORAGE");
}
if(new File(path).exists())
{
File f = new File(path);
if(f.canWrite())
{
return path;
}
}
}
String sdPath = Environment.getExternalStorageDirectory().getPath();
if(new File(sdPath).exists())
{
return sdPath;
} else
{
File SDfiles = Environment.getExternalStorageDirectory(); // SDCards(内置和外置SDCard)
if(SDfiles != null)
{
File parentFile = SDfiles.getParentFile();
// 列出该父目录下的所有路径
File[] listFiles = parentFile.listFiles();
// 如果子路径可以写 就是拓展卡(包含内置的和外置的)
for (int i = 0; i < listFiles.length; i++)
{
if(listFiles[i].canWrite()
&& new File(listFiles[i].getPath()).exists())
{
return listFiles[i].getPath();
}
}
}
}
return null;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值