Android Question SQ1 access to SD card SQLite.s3db database

Richard S

Member
Greetings all. Although I have been a Visual basic programmer for many years (self-taught) and finally retired at 76yrs young I decided to try my hand at B4A. Years ago I made a program for my own use that uses a SQLite database. I would like to have access to that data on my Android smart phone. I seem to be OK creating the program with one MAJOR exception. I cannot figure out how to get the path to the database on the SD card. Eventually I would like to have access to the data on a cloud but for now I will simply copy the database to and from the Android and the home network. My phone is an A8 (2018) and my wife has an A20. I have been reading multiple posts on the subject but only get more confused each time as I find the posters twist the topics to address their specific issues. As I am VERY new to smart phone programming I would really appreciate a simple step-by-step walk through getting me to where I can get the actual path to insert in the SQL1.Initialize(PalmTwo_Path, "PalmTwo.s3db", True)
I declared the PalmTwo_Path variable as a Public string
If anyone is willing to create a step-by-step tutorial I will be most grateful.
Keep well and stay safe.
Richard
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I recommend you to:

1. Store the database in File.DirInternal.
2. Add an option to zip the three database files (Archiver) and share them with an intent (FileProvider).
It is quite simple to implement.

Another option is to enable the legacy external storage feature and store the database in File.DirRootExternal: android.jar / targetSdkVersion / minSdkVersion
 
Upvote 0

Richard S

Member
SOLVED!
Thank you Erel. You put me on the right path.
I used RuntimePermissions.GetSafeDirDefaultExternal to get the folder where I needed to copy my existing SQLite. I then used
tools B4A Bridge > File Explorer to copy the SQLite database from my server to then folder on my Android that was returned.
I now have full access to the database on my Android.
 
Upvote 0

Albert Kallal

Active Member
Licensed User
Tools B4A Bridge > File Explorer

Geesh! - talk about a face plant. As Gomer Pyle would say? Gooooolllllly!

I missed that feature - been plugging in my phone with USB cable, or pulling the SD card.

Right in front of my nose all this time!!!

Wonderful feature!!! One I missed!!! just used it, and sure enough - works fantastic!

As noted, just keep in mind that Android now tends to restrict the folders to "just your" application you choose. This is done since if you install my software, it not going to rummage around other files and steal that data, or send it up some place. This is also why web browser code can NOT set the file name in JavaScript to choose a file (only the user can). This again prevents the web browser from stealing all your files while you visit a web site to watch some cat videos.

So as a FYI - this is why the files are restricted, and you can't just open + use any old file like you can on windows. So Android OS has adopted a similar approach to how web browsers work - only the user can select the files - not your code. However, you can browse/list the files in that folder - just not everything else on the SD card or memory.

Anyway - sounds silly - but I missed the bridge having a file explorer - go figure!!!

Thanks for sharing!

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Upvote 0

Shelby

Well-Known Member
Licensed User
When I use tools>b4a bridge>file explorer, the file explorer icon is not activated. How does one use that?
 
Upvote 0

Shelby

Well-Known Member
Licensed User
You have to be connected to the device via B4ABridge first, then the option becomes enabled
Thanks, but then the IDE says make sure your FTP server is enabled in the b4a-bridge app. Checking........... my unpublished app displays fine with the bridge; I would only guess that tells me the FTP is enabled.?
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
hen the IDE says make sure your FTP server is enabled in the b4a-bridge app. Checking.........
B4ABridge on you pc screen has a a line: Enable FTP Server. Mine is checked by default. Put a check if it is not. I do not have an FTP server on my PC. Everything works fine. I can copy files from tablet to PC and vice versa.
 
Upvote 0
Top