Wednesday, October 12, 2011

[android-developers] Re: Writing to External Storage Help

That still should work fine.

/mnt/sdcard on the Bionic is the internal memory and will never be removed so you shouldn't have any issue using it unless there is something wrong with the hardware.

/mnt/sdcard-ext is the SD card itself and can be mounted/unmounted etc.

You can try something like this to see what is available to you:

File fMount = new File( "/mnt" );
File[] fMountPoints = fMount.listFiles();
for( File fCheck : fMountPoints )
{
Log.i( "SDCheck", "Found: " + fCheck.getName() + " - Writable: " + fCheck.canWrite() );
}

I tried this on my Bionic and it worked great and everything in there is not writable except the two "SD Card" mount points.

I haven't found a way to get the system to tell me if there is more than one "SD Card" mounted. Since even the internal memory on devices is now showing as the "SD Card", hopefully ICS will give us a way to figure this out better.

Unless someone else knows how to get Android to tell you about the "SD Cards" mount points, you can use the above to find out which directories are writable to you and these should be the "SD Cards". I don't think they will be changing the /mnt mounting point any time soon, but you never know, so just be on the lookout if you use this. You may want to filter out anything starting with a dot also. I found there is some hidden and writable (or at least marked writable) files/directories in there on at least one of my devices that's a dot file.

You can always find the places you can write with that and give your users a chance to pick which one they want for your application to use.

Steven
Studio LFP
http://www.studio-lfp.com


On Tuesday, October 11, 2011 9:53:53 PM UTC-5, BJGApps wrote:
I have an app on the market and recently have had some reports of
problems writing to the SD. What appears to work completely fine on
some phones has proven not to work on others.

I have done some searching on this and really need some advice to help
make sure I am on the correct path.

I am using Environment.getExternalStorageDirectory() to get the
directory of the SD card. As I have read, this is the preferred method
to get the path of external storage. From there I am creating a
directory, a sub directory, and moving a file. This works perfectly
fine for a majority of users, however more recently I have had reports
of it failing this process.

Two examples were the Atrix and the Bionic.

It appears that some devices are reporting wrong information when
using Environment.getExternalStorageDirectory(). It appears to return /
mnt/sdcard when in reality it looks like the path should be /mnt/
sdcard-ext. This causes an exception to occur where it is trying to
make a directory in the wrong location.

Can someone shed some light on how I am supposed to handle this? Am I
supposed to be using something other than getExternal? What am I
supposed to do if the devices return wrong information? I really don't
want to have to tell someone its not my problem, contact their
manufacture.

Help me Android Developers, you're my only hope.

-BJGApps

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment