Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to differentiate between internal and external SD card path in android
    primarykey
    data
    text
    <p>In android application I need to do:</p> <pre><code>If(removable SdCard is present){ String path=get the path of removable Sdcard() ; //using this path we will create some files in sdcard } else{ //display error message } </code></pre> <p>To achieve this we used the code as:</p> <pre><code>If (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)){ String path= Environment.getExternalStorageDirectory().getPath(); } </code></pre> <p>The above code fails in some of latest android mobiles. Please help us on this.</p> <p>Below are the details of what we have tried:</p> <ul> <li>In android mobiles having OS of ICS and JellyBean, the exact path of the removable sdcard varies because of device manufacturer.</li> </ul> <p>See the table below</p> <pre><code>Tested Devices OS version removable sdcard path internal sd path Samsung galaxy s2 4.0.4 /mnt/sdcard/external_sd /mnt/sdcard Samsung S Advance 4.1.2 /storage/extSdCard /storage/sdcard0 Samsung Galaxy s3 4.0.4 /mnt/extSdCard /mnt/sdcard Samsung Galaxy Note 4.0.4 /mnt/sdcard/external_sd /mnt/sdcard </code></pre> <p>When running the above code in these devices we got:</p> <ul> <li><p>The android API Environment.getExternalStorageDirectory().getPath() returns only the internal sd path </p></li> <li><p>Also the the API Environment.getExternalStorageState() return Environment.MEDIA_MOUNTED in above devices even though sdcard is removed.</p></li> <li><p>Further the API Environment.isExternalStorageRemovable() always returns false for above devices whether removable sdcard is present or not.</p></li> </ul> <p>We searched in google and tried some functions they given.It gives only list of storage paths that are mounted to the device.But it doesnot indicate whether the removale sdcard is present or not.</p> <p>The function i tried to get the storage path:</p> <pre><code>private static String getMountedPaths(){ String sdcardPath = ""; Runtime runtime = Runtime.getRuntime(); Process proc = null; try { proc = runtime.exec("mount"); } catch (IOException e1) { e1.printStackTrace(); } InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); String line; BufferedReader br = new BufferedReader(isr); try { while ((line = br.readLine()) != null) { if (line.contains("secure")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) {//TF card String columns[] = line.split(" "); if (columns != null &amp;&amp; columns.length &gt; 1) { mount.add(columns[1]); sdcardPath=columns[1]; } } else if (line.contains("fuse")) {//internal storage String columns[] = line.split(" "); if (columns != null &amp;&amp; columns.length &gt; 1) { mount.add(columns[1]); } } } } catch (IOException e) { e.printStackTrace(); } return sdcardPath; } </code></pre> <p>Is there any other function better than above to get the list of storage paths in android ? also help to solve the above problem .</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload