gpt4 book ai didi

android - 在Android中获取辅助外部存储设备的公共(public)/根目录?

转载 作者:行者123 更新时间:2023-11-30 00:22:59 30 4
gpt4 key购买 nike

在 android 中,我可以使用以下方法获取手机的可移动外部存储:

for (File f : context.getExternalFilesDirs("/")) 
if (Environment.isExternalStorageRemovable(f))
Log.println(Log.DEBUG, "#", f.getAbsolutePath());

但是,这返回 /storage/8E6A-06FF/Android/data/test.application/files 这不是我想要的,因为我只想要可移动的根路径 /storage/8E6A-06FF/。如何获取手机移动存储的根路径?

最佳答案

你可以试试这个,它对我来说非常有用。它对所有操作系统版本都非常有用。到目前为止,我没有发现这个功能有任何问题。

public static String getSDPath() {
String filepath = "";
String[] strPath = {"/storage/sdcard1", "/storage/extsdcard",
"/storage/sdcard0/external_sdcard", "/mnt/extsdcard",
"/mnt/sdcard/external_sd", "/mnt/external_sd",
"/mnt/media_rw/sdcard1", "/removable/microsd", "/mnt/emmc",
"/storage/external_SD", "/storage/ext_sd",
"/storage/removable/sdcard1", "/data/sdext", "/data/sdext2",
"/data/sdext3", "/data/sdext4", "/emmc", "/sdcard/sd",
"/mnt/sdcard/bpemmctest", "/mnt/sdcard/_ExternalSD",
"/mnt/sdcard-ext", "/mnt/Removable/MicroSD",
"/Removable/MicroSD", "/mnt/external1", "/mnt/extSdCard",
"/mnt/extsd", "/mnt/usb_storage", "/mnt/extSdCard",
"/mnt/UsbDriveA", "/mnt/UsbDriveB"};

for (String value : strPath) {
File f = null;
f = new File(value);
if (f.exists() && f.isDirectory()) {
filepath = value;
break;
}
}
return filepath;
}

关于android - 在Android中获取辅助外部存储设备的公共(public)/根目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45935716/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com