Android Question Adding a datafile to an application

Sannie72

Member
Licensed User
Longtime User
Hello,

I would like to add a datafile (SQL file) to my app so the user can lookup (address) data from the database. This file needs to available on the first startup. Afterwards the user needs to be able to change the file.
How can I include a file in the final APK, and have it extracted when the APK is installed?
 

mangojack

Expert
Licensed User
Longtime User
Add a copy of your db to your project .. click on the Files Tab (see image)

Then ...
B4X:
Sub Activity_Create(FirstTime As Boolean)
 
  If FirstTime  Then
   
    If File.Exists(File.DirInternal, "Database.db") = False Then   'or (File.DirDefaultExternal,
       File.Copy(File.DirAssets, "Database.db", File.DirInternal, "Database.db")
     End

then use this path for all future read / writes... (File.DirInternal, "Database.db")
 

Attachments

  • Add Files Tab.PNG
    5.3 KB · Views: 140
Last edited:
Upvote 0

Sannie72

Member
Licensed User
Longtime User
Thanks mj, just what I needed. I missed the file.copy...

Cheers!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…