Problems Testing Code for SD Card Storage and Internal Flash Storage

I'm trying to write code 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 Internal Flash if available.

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. But this handset does 
not have internal flash storage available for storing shared files (Public 
internal flash storage that a PC or Mac can mount) so I can not test that 
part of the code.

Can 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to