![](/img/trans.png)
[英]How to delete file or directory from root directory of external storage (...removable sdcard root directory)
[英]How to get external REMOVABLE storage path (micro sdcard)
我正在构建一个媒体播放器应用程序,我想从设备上的 all.mp3 文件中列出一个列表。 为此,我需要 EXTERNAL REMOVABLE 存储路径。
此路径在不同设备中可能不同。
Environment.getExternalStorageDirectory().getAbsolutePath()
我已经尝试过上面的代码行,但它返回了内部存储的路径。
此处已对此进行了讨论。 它没有帮助。
你可以通过
public static String getExternalSdCardPath() {
String path = null;
File sdCardFile = null;
List<String> sdCardPossiblePath = Arrays.asList("external_sd", "ext_sd", "external", "extSdCard");
for (String sdPath : sdCardPossiblePath) {
File file = new File("/mnt/", sdPath);
if (file.isDirectory() && file.canWrite()) {
path = file.getAbsolutePath();
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmmss").format(new Date());
File testWritable = new File(path, "test_" + timeStamp);
if (testWritable.mkdirs()) {
testWritable.delete();
}
else {
path = null;
}
}
}
if (path != null) {
sdCardFile = new File(path);
}
else {
sdCardFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
}
return sdCardFile.getAbsolutePath();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.