如何在Android 6.0棉花糖中获取USB目录文件路径? [英] How to get USB Directory file path in Android 6.0 Marshmallow?
本文介绍了如何在Android 6.0棉花糖中获取USB目录文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在6.0中获取USB OTG的文件路径?
How to get file path of USB OTG in 6.0?
我无法在USB OTG中获取Android 6.0的文件路径,所以让我知道什么是解决方案?
I am not able to get file path of Android 6.0 in USB OTG so let me know what is solution?
谢谢, 吉里什
推荐答案
通过以下代码获取所有已安装的设备:
get all mounted devices by this code:
public String getStoragepath() {
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
String[] patharray = new String[10];
int i = 0;
int available = 0;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
String mount = new String();
if (line.contains("secure"))
continue;
if (line.contains("asec"))
continue;
if (line.contains("fat")) {// TF card
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + "/requiredfiles");
patharray[i] = mount;
i++;
// check directory is exist or not
File dir = new File(mount);
if (dir.exists() && dir.isDirectory()) {
// do something here
available = 1;
finalpath = mount;
break;
} else {
}
}
}
}
if (available == 1) {
} else if (available == 0) {
finalpath = patharray[0];
}
} catch (Exception e) {
}
return finalpath;}
这篇关于如何在Android 6.0棉花糖中获取USB目录文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文