Android Question Copy file to USB stick error

LuigiTasca

Member
Licensed User
Longtime User
I have to copy a file in the Internal Directory to a USB stick. To select the destination path I use "ExternalSotorage" library.
When I have selected the destination directory then I use ABzipunzip to zip the file, using the internal memory for source and the USB stick for destination, but it doesn't zip it.
So I tried only to copy the file from the internal directory to the usb stick and I get this error:

Error occurred on line: 4520 (Settings)
java.io.FileNotFoundException: /storage/7AC0-1DFD/dbs/Genial_Food.db (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:341)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

For the permissions I use:
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
And
B4X:
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)

Could you help me?

Thank you.
 

LuigiTasca

Member
Licensed User
Longtime User
Update: I think that this is a device problem (a retail POS). If I use another application from the PlayStore It get the same error.
Do you think I can get around this? Should I contact the producer?
 
Upvote 0

LuigiTasca

Member
Licensed User
Longtime User
About the link you mean to use "ExternalStorage" library? I already use it and in the most devices it works.
 
Upvote 0

LuigiTasca

Member
Licensed User
Longtime User
i dont think that you can use abzipunzip to work on the external sdcard.
It needs to use the StorageAccessFramework to work. at least on higher android versions.

Zip it internal and then copy the ZIP to the sdcard using the SAF.

I tried to use only File.Copy without ABzip and it get the same error. And third parts file browser applications get the same error.
How Can I copy a file using the ExternalSorage Class? I'm able only to list files and select dirs
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried to use only File.Copy without ABzip and it get the same error.
it is expected on higher android versions.

AGAIN:

YOU NEED to use the StorageAccessFramework (SAF).

Starting from Android 4.4 it is no longer possible to directly access external storages.
The only way to access these storages is through the Storage Access Framework (SAF), which is a quite complex and under-documented framework.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…