If I understand you correct .. If you have changed the code as suggested above ..
Yes ... All is Good . you only have to save the db elsewhere (File.DirInternal) or search forum to solve saving to External SD.
If I understand you correct .. If you have changed the code as suggested above ..
Yes ... All is Good . you only have to save the db elsewhere (File.DirInternal) or search forum to solve saving to External SD.
You did not follow instructions above to change your code ... See post #17.
Your Code
B4X:
sql1.Initialize(File.DirInternal,"savedata.db",True)
If File.Exists(File.DirInternal,"savedata.db")=False Then
File.Copy(File.DirAssets,"savedata.db",File.DirDefaultExternal,"savedata.db") '@@ wrong DIR
End If
Should be ...
B4X:
If File.Exists(File.DirInternal,"savedata.db")=False Then
File.Copy(File.DirAssets,"savedata.db",File.DirInternal,"savedata.db")
End If
sql1.Initialize(File.DirInternal,"savedata.db",False) '@@ change to False .. the db should always exist now.
*** Uninstall old app first OR delete existing blank db on first run !
Also Please study the Starter Service which would be best place for above code (see uploaded project #21)
as you say i do but same issue but in my phone work saving data but not view data:
LogCat connected to: emulator-5554
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 334)
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1013)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
I don't think you need to root your phone. It may depend on which Android version that support external storage. My phone is not rooted and I usually develop my app to move the db file from asset to Internal and not external to reduce any problem with the storage permission.
The sqlite db is usually very small storage footprint (<1 Megabyte). I don't think app user mind to let it keep inside the internal storage.
Here is how my app normally written when loading at Main activity.
B4X:
Sub Process_Globals
Dim DB As SQL
Dim DBFileDir As String
Dim DBFileName As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
DBFileDir = File.DirInternal
DBFileName = "mytenant.db"
If File.Exists(DBFileDir, DBFileName) = False Then
DBFileDir = DBUtils.CopyDBFromAssets(DBFileName)
End If
DB.Initialize(DBFileDir, DBFileName, False)
End If
End Sub
I don't think you need to root your phone. It may depend on which Android version that support external storage. My phone is not rooted and I usually develop my app to move the db file from asset to Internal and not external to reduce any problem with the storage permission.
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.