Note that there are some explanatory texts on larger screens.

plurals
  1. PO`getExternalStorageDirectory()` issue - Android
    primarykey
    data
    text
    <p>I'm writing an android application that takes some pictures and would like to save them all in a unique directory associated to my application.</p> <p>This directory should be accessible from the standard Gallery, in such a way that the user can later (when application is not necessarily running) check the pictures that were taken.</p> <p>My problem is that every different phone vendor, with a different android version, has different paths for gallery.As an example:</p> <pre><code>Environment.getExternalStorageDirectory() + Environment.DIRECTORY_PICTURES +"/myFolder" </code></pre> <p>will work on <code>Samsung Galaxy Nexus</code> running <code>android 4.1.1</code>, and on <code>Asus Transformer Pad</code> running <code>android 4.0.3</code>, but not on <code>HTC Desire</code> running <code>android 2.3.5</code>.</p> <p>This will cause my application to crash when trying to save a new directory within the specified path, as stated below:</p> <pre><code>boolean success = false; myFolder = new File( Environment.getExternalStorageDirectory() + Environment.DIRECTORY_PICTURES + "/myFolder" ); if( myFolder.exists() ){ //do nothing }else{ success = dvaFolder.mkdir(); if( success ){ // Do something on success /* * folder has been created */ } else { // Do something else on failure /* * folder creation failed */ throw new RuntimeException("File Error in writing new folder"); } } </code></pre> <blockquote> <p>How can I write a directory that will be accessible in gallery for all different vendors and android versions?</p> </blockquote> <p><strong>NOTE:</strong></p> <p>Logcat isn't much useful, cause it just returns the run time Exception.</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.
 

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