Android Question Weird file access permission problem on SDK17

CaptKronos

Active Member
Licensed User
Longtime User
I have been testing one of my apps on Google's emulator under various different SDK platform levels and have stumbled upon weird behavior that is only shown under SDK17. The attached Project exhibits the problem however it simply consists of the following line:
B4X:
File.Copy(File.DirAssets, "b4a.png", File.DirRootExternal, "b4a.png")

On all SDK levels that I have tested (16, 17, 18, 19) the above line is successful (since there is the appropriate WRITE_EXTERNAL_STORAGE permission) apart from on 17. On 17 I get the error:

B4X:
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 43 (Main)
java.io.FileNotFoundException: /mnt/sdcard/b4a.png: open failed: EACCES (Permission denied)
    at libcore.io.IoBridge.open(IoBridge.java:416)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:373)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:339)
    at b4a.example.main._button1_click(main.java:410)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4204)
    at android.view.View$PerformClick.run(View.java:17355)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
    at libcore.io.IoBridge.open(IoBridge.java:400)
    ... 26 more
** Activity (main) Pause, UserClosed = true **

I have tried deleting and recreating the platform 17 AVD, but I still see the same error. Any ideas?

Thanks.
 

Attachments

  • twp.zip
    19 KB · Views: 205

DonManfred

Expert
Licensed User
Longtime User
1. Try it on a real device.
2. You did not add a permission in the Manifest.
Add this line to the manifesteditor
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE) ' Allows an application to write to external storage.
 
Upvote 0

CaptKronos

Active Member
Licensed User
Longtime User
Unfortunately I don't have a real device with SDK17.

Adding the permission to the manifest doesn't fix the problem. Also, clicking on List Permissions in the B4A IDE shows
the WRITE_EXTERNAL_STORAGE permission.
 
Upvote 0

CaptKronos

Active Member
Licensed User
Longtime User
I think you have cracked it. An sdcard is not mounted and clicking on Android's Settings and then Storage, results in an "Unfortunately, Settings has stopped." It looks like the AVD image is broken. I'll try with Visual Studio's Android emulator.
 
Upvote 0
Top