Do you have the permission for writing to external storage?

Also, it might not be a good idea to mimic standard Android directory names - there might be a collision if the user decides to move your application to the memory card.

Finally, do verity the pathname you pass to mkdirs(). If it's "/sdcardAndroid/data/etc." (without the path separator), that would be a pretty good reason for it to fail (attempting to create a new directory under file system root).

-- Kostya

30.10.2010 23:02, John Gaby пишет:
Thanks for the input.  I decided that the SD card is the proper place
for the files anyway, so I am trying to make that work.  Since I want
to support pre 2.2 versions, I am doing the following:

                String state = Environment.getExternalStorageState();

                if (Environment.MEDIA_MOUNTED.equals(state))
                {
                        File root = Environment.getExternalStorageDirectory();
                        File ext = new File(root, "Android/data/" +
m_activity.getPackageName() + "/files/");
                        boolean b = ext.mkdirs();
                        String s = ext.getAbsolutePath();

                         ...

Unfortunately, the ext.mkdirs() call is returning false, and the
directories are not being created.  I did a web search, and it seems
like this is the proper way to create my directory.  Do you have any
idea why it is not working for me?

Thanks.



On Oct 29, 11:19 pm, Mark Murphy<mmur...@commonsware.com>  wrote:
On Fri, Oct 29, 2010 at 6:03 PM, John Gaby<jg...@gabysoft.com>  wrote:
If I have a File object which points to a non-existent directory
(which is within my apps 'app_data' space), I can call file.mkdir() or
file.mkdirs() to create the directories.  However, if I do this, the
directories seem to be created with permissions set for access only by
the owner (i.e. drwx------).  Then if I write a .mp3 file into that
directory, I cannot later play that .mp3 file using the MediaPlayer,
apparently because it does not have permission to read the file (note
that if I put the .mp3 file directly in the 'app_data' directory, it
works fine).  How can I set the permissions on the directories that I
create so that the MediaPlayer can access the files?
Literally, I think the only answer is:

Runtime.getRuntime().exec("chmod 755 " + fileName);

If you create files via openFileOutput(), you can specify permission
bits, but that only works for files immediately in the app-local file
store.

Or, put the files on the SD card.

Or, create a content provider that serves up the files to the
MediaPlayer. This is probably the best answer (does not assume
command-line binaries that may or may not exist).

--
Mark Murphy (a Commons 
Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy

Android 2.2 Programming Books:http://commonsware.com/books


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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