Android detects usb mount point path

I am working on an application that can connect to a USB card reader. The problem is that the USB path is not the same for all phones. I know that in Samsung phones the USB path is "/ storage / UsbDriveA /"

My question is how to find the USB connection path for all telephone devices?

Thank you

0
source share
1 answer
private String getAllStoragePath() { String finalPath = ""; try { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mount"); InputStream inputStream = process.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); String line; String[] pathArray = new String[4]; int i = 0; BufferedReader br = new BufferedReader(inputStreamReader); while ((line = br.readLine()) != null) { String mount = ""; if (line.contains("secure")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) {// TF card String columns[] = line.split(" "); if (columns.length > 1) { mount = mount.concat(columns[1] + "/someFiles"); pathArray[i++] = mount; // check directory inputStream exist or not File dir = new File(mount); if (dir.exists() && dir.isDirectory()) { // do something here finalPath = mount; break; } } } } for(String path:pathArray){ if(path!=null){ finalPath =finalPath + path +"\n"; } } } catch (Exception e) { e.printStackTrace(); } return finalPath; } 
+2
source

All Articles