Android Question Create a new folder and copy DB file from Assets into it

Phayao

Active Member
Licensed User
Longtime User
Hello,

maybe this is a trivial question, anyhow, I was not able to create a new folder on the internal sd card by using
DBFileDir = Storage.FindDirOrCreate(Storage.Root,"new")

I tried to modify the SaveAs example:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Storage.Initialize (Me, "Storage")
    DBFileDir.Initialize

End Sub

Private Sub Button1_Click
   DBFileDir = Storage.FindDirOrCreate(Storage.Root,"test")

    Wait For (SaveFile(File.OpenInput(File.DirAssets, "test.db"), "application/octet-stream", "test.db")) Complete (Success As Boolean)

    Log("File saved successfully? " & Success)
End Sub

Error message:
B4X:
Logger connected to:  vivo V2026
--------- beginning of crash
--------- beginning of main
--------- beginning of system
Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 58 (ExternalStorage)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
    at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1060)
    at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:417)
    at b4a.example.b4xpagesmanager._addpage(b4xpagesmanager.java:245)
    at b4a.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:259)
    at b4a.example.b4xpagesmanager._initialize(b4xpagesmanager.java:165)
    at b4a.example.main._activity_create(main.java:415)
    at java.lang.reflect.Method.invoke(Native Method)

The original SaveAs example worked well but I don't want the user choose a folder, the program should copy a file, actually a sqlite database, from the Assets folder into this new folder.

Sorry, but I got totally confused !

Any help is appreciated.

Chris
 

DonManfred

Expert
Licensed User
Longtime User
but I don't want the user choose a folder
THIS is how the External Storage class works. The Class only use Systemfeatures as defined by Google resp. Android.

The user MUST select the Path for you can work with it.
You can store the result and reuse it next time. But the Device-User must select the Root path once.

 
Upvote 0

Phayao

Active Member
Licensed User
Longtime User
Thanks Manfred - so this class is not useful in my case :-(
I will struggle with other ways, maybe its no longer possible to programmatically create a folder in the external sdcard.
 
Upvote 0
Top