Android Question [SOLVED] Where to put SQLite db file? My app crashes on Android 6.

Lee Gillie CCP

Active Member
Licensed User
Longtime User
The highest version we have run our app on is Android 5.0.1. The customer acquired a new tablet device running Android 6.0.2. While the app installs without issue, it fails during startup attempting to create its SQLite database:
B4X:
GlobalModule.Delivery.Initialize(GlobalModule.DeliveryPath,"Delivery.db",True)
Fails with
*** Service (starter) Create ***
ELJAY DELIVERY Starter.Service_Create
** Service (starter) Start **
ELJAY DELIVERY Starter.Service_Start
** Activity (main) Create, isFirst = true **
Data folder for application is /storage/emulated/0/Android/data/odp.eljaydelivery/files
Error occurred on line: 686 (DeliveryDBUtils)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at odp.eljaydelivery.globalmodule._init(globalmodule.java:76)
at odp.eljaydelivery.main._activity_create(main.java:610)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at odp.eljaydelivery.main.afterFirstLayout(main.java:104)
at odp.eljaydelivery.main.access$000(main.java:17)
at odp.eljaydelivery.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5484)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

So what did we compute for DeliveryPath?
GlobalModule.DeliveryPath is "/storage/emulated/0/Android/data/odp.eljaydelivery/files"

How did we come up with that?
B4X:
If File.ExternalWritable Then DataFilesPath = File.DirDefaultExternal Else DataFilesPath = File.DirInternal

I snooped around release notes for Android 6 but am not finding an item requiring mitigation to upgrade. Are new permissions required? Are we now blocked from storing app data here? Clearly this no longer works. Can someone point me in the right direction? I take it I will need to come up with a new home for the database.

Thanks in advance for any advice
 

Lee Gillie CCP

Active Member
Licensed User
Longtime User
FWIW - I added a permission to the manifest, but no change in behavior: WRITE_EXTERNAL_STORAGE
 
Upvote 0

Lee Gillie CCP

Active Member
Licensed User
Longtime User
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I notice older tablets run from the same APK with no issue

It depends on the target sdk. From 23+ you need to check if it's 23+ (=runtime permission) or lower (old way). It's about Google stating that from August this year this new method is needed otherwise you can't upload new apps to the Playstore.

If you have just inhouse apps which you install on your own you're good with the "old" way unless you do not need newer functions which need target sdk >=23.
 
Upvote 0
Top