[英]Environment.getExternalStorageDirectory().getAbsolutePath() return sdcard0 but I have my SD in sdcard1
I try to write something into SD Card phone memory using Environment.getExternalStorageDirectory().getAbsolutePath() to get the SD Path, and the result is /storage/sdcard0. 我尝试使用Environment.getExternalStorageDirectory()。getAbsolutePath()将一些内容写入SD卡电话内存,以获取SD路径,结果为/ storage / sdcard0。 But my SD Card is /storage/sdcard1. 但是我的SD卡是/ storage / sdcard1。 How to get the real SD Card path? 如何获得真实的SD卡路径?
I can see in "/" that there is a symbolic link called /ext_sd linked to /storage/sdcard1. 我可以在“ /”中看到一个名为/ ext_sd的符号链接,链接到/ storage / sdcard1。 This symbolic link is in all devices? 此符号链接是否存在于所有设备中?
I found the solution in this post: How can I get external SD card path for Android 4.0+? 我在这篇文章中找到了解决方案: 如何获取Android 4.0+的外部SD卡路径?
/**
* Returns the list of external devices mounted.
*
* @return HashSet<String>.
*/
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
Try this, 尝试这个,
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath()
+ "/Save PIP/");
dir.mkdirs();
File file = new File(dir, System.currentTimeMillis() + ".jpg");
// Utils.showAlert("Image Saved to SD Card", "PIP Effect", "Ok", FrameActivity.this);
if (file.exists()) file.delete();
try {
output = new FileOutputStream(file);
bitmap_final.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
here,You can get your sd card path.I wish it will help you and your solve your problem very soon. 在这里,您可以获取SD卡的路径。希望它能帮助您和您尽快解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.