I am not able get root path usb otg in Android Nougat working fine till marshmallow. even able to get root path of sd card .can any body help me out from this i am frustrated from couple days.
Here is my code that return root path upto marshmallow and nougat sdcard. but not usb otg
public static String FileSystem() {
String path = null;
String SD_CARD_DIR = null;
try {
Process mount = Runtime.getRuntime().exec("mount");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mount.getInputStream()));
mount.waitFor();
// String extPath = Environment.getExternalStorageDirectory().getPath();
// String isMedai = Environment.getExternalStorageState();
// if(Environment.MEDIA_MOUNTED.equalsIgnoreCase(isMedai)){
// String root = Environment.getRootDirectory().getPath();
// path = Environment.getExternalStoragePublicDirectory(DIRECTORY_EDUCOMP).getPath();
// }
String line;
String strFileSystem = null;
while ((line = bufferedReader.readLine()) != null) {
String[] split = line.split("\\s+");
for (int i = 0; i < split.length - 1; i++) {
if (SD_CARD_DIR == null) {
File mainroot = new File(split[i]);
File f[] = mainroot.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return new File(dir, name).isDirectory();
}
}); // Get First level folders /mnt
if (f != null) {
for (File aFile : f) {
File[] filenames = aFile.listFiles(); // Get second level
// folders
// /mnt/sdcard so on
// and math Educomp
// folder
if (filenames != null) {
for (File ff : filenames) {
String eduFileName = ff.getName();
if (eduFileName.equals("Temp")) {
File[] listEducompfile = ff.listFiles();
if (listEducompfile != null) {
for (File fff : listEducompfile) {
String contentFileName = fff.getName();
if (contentFileName.equals("ts")) {
SD_CARD_DIR = aFile
.getAbsolutePath() + "/";
break;
}
}
}
} else {
File[] filenamesList = ff.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return new File(dir, name).isDirectory();
}
});
if (filenamesList != null) {
for (File fff : filenamesList) {
String eduFileNamess = fff.getName();
if (eduFileNamess.equals("Temp")) {
File[] listEducompfile = fff.listFiles();
if (listEducompfile != null) {
for (File fffds : listEducompfile) {
String contentFileName = fffds.getName();
if (contentFileName.equals("ts")) {
return SD_CARD_DIR = ff + "/";
}
}
}
}
}
}
}
}
}
}
}
}
// SD_CARD_DIR = DEFAULT_SD_CARD_DIR;
}
return SD_CARD_DIR;
}
return path;
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}