Android Question Saving "external" folder choice for subsequent access

mtechteam

Member
Licensed User
Longtime User
Referencing Erel's tutorial:

[B4X] TextEditor - Save and load external files​


Is it possible to retain the selection made and use it in the future for the same app (after restarts, etc.) so that the user is not prompted more than once?
 

mtechteam

Member
Licensed User
Longtime User
I've got it working, mostly. Occasionally, especially in debug mode, the Copy2 function when copying an SQLite database, only copies part of it, rendering it unable to be opened. Other tests on text files, XML files, Json files, etc. seem to be working fine. Could be related to the size, the SQLite database is 2.4 MB.
 
Upvote 0

mtechteam

Member
Licensed User
Longtime User
Here is the pertinent code. The ExternalStorage library is selected and
#AdditionalJar: androidx.legacy:legacy-support-core-utils
is added to the beginning of the "Main" class (B4XPages project, B4A build)

External Storage:
  (in B4XMainPage)
  BookletCalls.Storage.Initialize (Me, "Storage")

.....
   (in B4XMainPage)
    BookletCalls.Storage.SelectDir(True)
    Wait For Storage_ExternalFolderAvailable


.....
  (Module Called BookletCalls)
    Dim ef As ExternalFile
    Dim os As OutputStream
    Dim is1 As InputStream

    ef = Storage.FindFile(Storage.Root, Filename)
    If ef.IsInitialized = True Then
        Storage.DeleteFile(ef) ' Remove old one if its there
    End If

    ef = Storage.FindFileOrCreate(Storage.Root, Filename)
    os = Storage.OpenOutputStream(ef)
    If File.Exists(MTT.FileFolder, Filename) = True Then
        is1 = File.OpenInput(MTT.FileFolder, Filename)
        File.Copy2(is1, os)
        Log("Backup made: " & Filename)
    End If
    os.Flush
    os.Close
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Copy2 (In As java.io.InputStream, Out As java.io_OutputStream)​

Copies all the available data from the input stream into the output stream.

The input stream is automatically closed at the end.

Have you tried to close the outpustream after the Copy2-Line?
 
Upvote 0

mtechteam

Member
Licensed User
Longtime User
Just when I'm about to write a reply that I figured it out, it doesn't quite work.

It seemed to work better creating just a B4a project rather than B4Xpages, but that fails some too.

Then I was looking at having a pause between each step. The sample program requires two clicks, one to select the folder (or use what's there) and a click to select the file you want to copy.

What is new in what I am doing, is copying from internal to external. The sample project goes the other way. Perhaps that is the defect?

Stumped.....

Here is the simplest project. The file is just data, so I think making sure it is > 3MB should be all you need to reproduce. I am using a G7 ThinQ. And as I write this, see that it is on Android 9. So I then tried it on a Pixel 4 XL on Android 13 and it works great. 10 copies all complete. Going right back to test on G7, 7 copies 3 were good, 4 were some degree of size smaller.

Any help would be greatly appreciated.
 

Attachments

  • BackupDefault.zip
    9.3 KB · Views: 36
Upvote 0
Top