Android Question DBUtils sample does not work when set to use android:targetSdkVersion="31"

tseyfarth

Member
Licensed User
Longtime User
Hello all,

I was playing with the DBUtils sample and have found that when the SDK version is set to what the IDE suggests - 31 causes this code to not work correctly. It retrurns a failure code

B4X:
Sub Service_Create
    File.Delete(File.DirRootExternal, "1.db")

When set to SDK Version 14, as it is supplied, it works fine. How to make it work correctly with SDK 31?

Thanks
Tim
 

Mahares

Expert
Licensed User
Longtime User
When set to SDK Version 14, as it is supplied, it works fine. How to make it work correctly with SDK 31?
It will not work. You have to replace everywhere: File.DirRootExternal with either one of these 2:
xui.DefaultFolder or File.DirInternal
 
Upvote 1

JohnC

Expert
Licensed User
Longtime User
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Changes to Android for security and privacy mean mean that File.DirRootExternal is no longer available to programs targetting SDK 31. See post #2 above.
But it seemed like he tried using the alternate paths in suggestion in post #2 and it didn't work (post #4).
 
Upvote 0

softmicro

Member
Licensed User
Longtime User
Hello
I have bought an android 13 (Api 33) and it generates the error in DbUtils that does not occur in any other version of Android or API.

In the function:

Sub ExecuteMemoryTable(SQL As SQL, Query As String, StringArgs() As String, Limit As Int) As List
Try
Dim cur As Cursor
If StringArgs <> Null Then
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
End If
'Log("ExecuteMemoryTable: " & Query)
Dim table As List
table.Initialize
If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
For row = 0 To Limit - 1
cur.Position = row
Dim values(cur.ColumnCount) As String
For col = 0 To cur.ColumnCount - 1
values(col) = cur.GetString2(col)
Next
table.Add(values)
Next
cur.Close
Return table

Catch
Log(LastException)
End Try
End Sub

it returns me this error:

(SQLiteException) android.database.sqlite.SQLiteException: no such table: Parameters (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM Parameters WHERE RomNumSerieModulo LIKE '%125815%'
main_timaction_tick (java line: 17930)
java.lang.NullPointerException: Attempt to invoke virtual method 'int anywheresoftware.b4a.objects.collections.List.getSize()' on a null object reference
at control.wiaction.gonner.main._timaction_tick(main.java:17930)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7941)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015)

Any suggestions or help for this problem?
Thank you.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Please post problems in a new thread and not add to an unrelated old one.

I am puzzled by that stack trace as it seems the error occurs in your Timer Tick event and not the Sub you have posted. More information required, although if it works on lower APIs without it is probably a memory permission as memory access is very limited in later APIs. Where is your database located?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…