Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>private String getExternalSDPath() { File file = new File("/system/etc/vold.fstab"); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(file); } catch (FileNotFoundException e) { // handle } String path = null; try { if (fr != null) { br = new BufferedReader(fr); String s = br.readLine(); while (s != null) { if (s.startsWith("dev_mount")) { String[] tokens = s.split("\\s"); path = tokens[2]; // mount_point if (Environment.getExternalStorageDirectory() .getAbsolutePath().equals(path)) { break; } } s = br.readLine(); } } } catch (IOException e) { // handle } finally { try { if (fr != null) { fr.close(); } if (br != null) { br.close(); } } catch (IOException e) { // handle } } return path; } </code></pre> <p>The code is made specifically for Samsung Devices with both internal, an internal that acts as external, and SD.</p> <p>I needed to access the SD and came up with the above code, so you can try it and possibly modify it to work on all devices.</p> <p><strong>Edit:</strong> My download AsyncTask</p> <pre><code> private class DownloadFile extends AsyncTask&lt;Void, Void, String&gt; { @Override protected String doInBackground(Void... params) { String filename = "somefile.pdf"; HttpURLConnection c; try { URL url = new URL("http://someurl.com/" + filename); c = (HttpURLConnection) url.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); } catch (IOException e1) { return e1.getMessage(); } File myFilesDir = new File(Environment .getExternalStorageDirectory().getAbsolutePath() + "/Download"); File file= new File(myFilesDir, filename); if (file.exists()) { file.delete(); } if ((myFilesDir.mkdirs() || myFilesDir.isDirectory())) { try { InputStream is = c.getInputStream(); FileOutputStream fos = new FileOutputStream(myFilesDir + "/" + filename); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = is.read(buffer)) != -1) { fos.write(buffer, 0, len1); } fos.close(); is.close(); } catch (Exception e) { return e.getMessage(); } } else { return "Unable to create folder"; } } @Override protected void onPostExecute(String result) { Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG) .show(); super.onPostExecute(result); } } </code></pre>
    singulars
    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