Android Question Copy file to USB stick error

Discussion in 'Android Questions' started by LuigiTasca, Apr 15, 2019.

Tags:
  1. LuigiTasca

    LuigiTasca Member Licensed 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:
    Code:
    AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
    AddPermission(android.permission.READ_EXTERNAL_STORAGE)
    And
    Code:
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Could you help me?

    Thank you.
     
  2. LuigiTasca

    LuigiTasca Member Licensed 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?
     
  3. DonManfred

    DonManfred Expert Licensed User

  4. LuigiTasca

    LuigiTasca Member Licensed User

    About the link you mean to use "ExternalStorage" library? I already use it and in the most devices it works.
     
  5. DonManfred

    DonManfred Expert Licensed 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.
     
    Erel likes this.
  6. LuigiTasca

    LuigiTasca Member Licensed User

    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 :confused:
     
  7. DonManfred

    DonManfred Expert Licensed User

    it is expected on higher android versions.

    AGAIN:

    YOU NEED to use the StorageAccessFramework (SAF).

     
  8. LuigiTasca

    LuigiTasca Member Licensed User

    Ok, that works. Thank you
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice