Android Question [Solved] Problem with File.copy to DirRootExternal on Marshmallow Devices

fredo

Well-Known Member
Licensed User
Longtime User
Could someone give me a hint how to solve this?

When I try
B4X:
File.Copy(File.DirAssets, FileName, File.DirRootExternal, FileName)
on Marshmallow (API 23) devices I get this error:
java.io.FileNotFoundException: /storage/emulated/0/dbfb1.rst: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:370)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:336)
at b4a.example.main._ratest0(main.java:447)
at b4a.example.main._activity_resume(main.java:330)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at b4a.example.main.afterFirstLayout(main.java:106)
at b4a.example.main.access$100(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
... 18 more
java.io.FileNotFoundException: /storage/emulated/0/dbfb1.rst: open failed: EACCES (Permission denied)
Even the Manifest entry
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
has no effect.

I used the Visual Studio Emulator for this, since I have no real Marshmallow device on hand.

The interesting part is that the error does not appear on devices with API < 23.

So I think it could have something to do with the new security model for android but I can't get a grip on that.

Enclosed is a screenshot and a short project.
 

Attachments

  • MarshmallowDirExternal.png
    MarshmallowDirExternal.png
    129.9 KB · Views: 790
  • MarshmallowDirExternal.zip
    11.8 KB · Views: 365
  • aaafredotest.apk
    142.8 KB · Views: 265
Top