Android Question How to write or delete files on external sd with KITKAT

cb56

Member
Licensed User
Longtime User
Hi,
with KITKAT seems that non-system app can't write to external sd card.

Using "File.Copy" I get this error: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

I noticed for example that the developer of QuickPic (the famous app to view images) in the latest release has solved the problem.

Is there any solution with b4a?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
I have KitKat and i´m able to save files to File.DirRootExternal without problems...
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I haven't noticed that problem, what filepaths are you copying from and to?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just did a test using:

B4X:
File.Copy("/storage/sdcard0/","sign.png","/storage/sdcard0/","sign1.png")

And it worked.

My File.DirRootExternal reports /storage/emulated/0
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you checked that the name hasn't changed with a file manager? I know it shouldn't but.......
 
Upvote 0

cb56

Member
Licensed User
Longtime User
My File.DirRootExternal reports /storage/emulated/0 too, but is INTERNAL SD

/storage/sdcard0 is INTERNAL SD

Is a known issue, look here: http://forum.xda-developers.com/showthread.php?t=2617921

I've Seen this solution, anyone can convert it in B4A?: http://forum.xda-developers.com/showthread.php?t=2634840

EDIT: I've found another problem with KITKAT: "File.Delete" does not delete the files on the external sd card and do not raise error!

The workaround for now is to use "If File.Exists" even after attempting to delete...

This should be solved...
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is nothing to solve or that can be solved. It is explained here: http://source.android.com/devices/tech/storage/index.html

If you want to write to a removable external card then you can only write to a folder based on your package name.

File.DirRootExternal / DirDefaultExternal continue to work properly.
 
Upvote 0

cb56

Member
Licensed User
Longtime User
There is nothing to solve or that can be solved. It is explained here: http://source.android.com/devices/tech/storage/index.html

If you want to write to a removable external card then you can only write to a folder based on your package name.

File.DirRootExternal / DirDefaultExternal continue to work properly.

Thanks Erel,
this is a huge problem in KITKAT.

I'll try to ask the developer of QuickPic because I assure you that, in the latest release, QuickPic writes correctly in any folder on the external sd with KITKAT.

Nonetheless, "File.Delete" do not delete files and do not raise any error when you try to delete files on External sd, maybe this should be fixed.

cb56
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.Delete returns True if the file was successfully deleted. You should check the return value.

File.Delete implementation:
B4X:
public static boolean Delete(String Dir, String FileName) {
     return new java.io.File(Dir, FileName).delete();
   }
As you can see it just calls the native API. If the native API fails then there is nothing that can be done.
 
Upvote 0

Paulsche

Well-Known Member
Licensed User
Longtime User
There is nothing to solve or that can be solved. It is explained here: http://source.android.com/devices/tech/storage/index.html

If you want to write to a removable external card then you can only write to a folder based on your package name.

File.DirRootExternal / DirDefaultExternal continue to work properly.

Are there plans to solve the problem in B4A?
Users ask for a solution in order to continue backing up to ext.SDcard from my APPs. I do not know what I can answer.
 
Upvote 0

Paulsche

Well-Known Member
Licensed User
Longtime User
Read my answer above. This is not a B4A issue.

This is how Google designed Android 4.4: https://plus.google.com/ TodLiebeck/posts/gjnmuaDM8sn

Starting from Android 4.4 you can only write to a folder based on your package name (on SD cards).

Thanks Erel,

I have already read, but has been adapted to other APPs that the writing on ext.SDcard working again, so it must be a way
or do I see this wrong?
How can I prevent that user a path of ext.SDcard as a backup path choose? Currently, you can always get an error.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Last edited:
Upvote 0

cmweb

Active Member
Licensed User
Longtime User
I can only repeat my previous answers. Starting from Android 4.4 you can only save on the SD card under one specific folder.
This is how Google designed it.

There are many frustrated developers as you can see here: https://code.google.com/p/android/issues/detail?id=65610&can=1&q=4.4 sd card&colspec=ID Type Status Owner Summary Stars
Hi Erel,

it seems that some developers have managed to workaround this restriction. For example, Total Commander file manager fixed the problem with writing to external SD card in the latest beta version of the app:

http://www.ghisler.com/android.htm

So, maybe we can also have a solution for this serious problem?

Best regards,

Carsten
 
Upvote 0
Top