Hello Android Developers,

I'm trying to write code for the app I'm developing, that will store *User 
Created files* on
the SD card if it is available. If the SD card is not available, it will 
store the files on
the devise Internal Flash if it is available. Also, these User Created 
files must be stored
in a location where they will not be automatically deleted when the app is 
removed.

My code:

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
        
// Try to make directory on the SDcard.
subdirectory = Environment.getExternalStoragePublicDirectory("MyDirectory");
    
// Make sure the directory exists.
subdirectory.mkdirs();

} else  {

// Try to make a directory on device internal flash storage.
subdirectory = Environment.getExternalStoragePublicDirectory("MyDirectory");

// Make sure the directory exists.
subdirectory.mkdirs();
          
}

File pathAndFileName = new File(subdirectory, FileName);

FileWriter writer = new FileWriter(pathAndFileName);
BufferedWriter out = new BufferedWriter(writer);
out.write("\n" + ReportUpdate + "\n");
out.close();


I'm developing this app using *API Level 8* and testing the app on a 
Samsung Intercept
running *Android 2.2.2*. 

When I test this code on the Samsung Intercept it successfully makes a 
directory on
the SD card and will read/write files.

*The problem is:* The Samsung Intercept is the only handset I have access 
to and it
does not have internal flash storage available for storing shared files
(Public internal flash storage that a PC, Mac or Linux box can mount) so I 
can not
test that part of the code.

*Will some developers please test this code and provide feedback on the 
results?*
Please test this code on:

   - Handset models that have both SD card and internal flash storage.
   - Older handsets that do not have SD card.

Please also let me know if there are errors or other problems with my code.

*Reference to using the methods:* 
getExternalStorageState()  and  getExternalStoragePublicDirectory()
http://developer.android.com/reference/android/os/Environment.html#getExternalStorageState()

Thank you for helping  :)


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to