0

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

My question is how can I find the USB mount path for all phone devices?

thank you

3
  • I think there no direct API from android to find out the connected USB devices. May be this can help you. Commented Dec 29, 2015 at 15:03
  • hi thank you for the referral I'm going to check it out Commented Dec 29, 2015 at 15:10
  • If the device is actually mounted in such a way as to be available to your app, it will be in your app process's version of /proc/mounts which can be read as a text file. But don't assume that the device is literally mounted for you app (it may only be mounted for other process ancestries, or not actually mounted but rather interacted with using non-File code) and keep in mind that you will see a somewhat different /proc/mounts when exploring with adb than your app sees. Commented Dec 29, 2015 at 15:19

1 Answer 1

2
 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; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.