Android Question How to put two filters in read SMS URI

atulindore

Member
Licensed User
Longtime User
How can I put date condition in below code (Cursor ) .. I want to read SMS only for last 10 days . Epoch Seconds for 10 Days : 864000.
B4X:
Sub GetSMS(SMSstr As String) As List
    Dim SMSList As List
    Dim Msgid,MsgDt As String
    Dim MsgFrom , MsgBody As String
    SMSList.Initialize
    Dim ur As Uri
    ur.Parse("content://sms")

    Dim crsr As Cursor = cr.Query(ur,Array As String("_id","date","address","body"),"address = ?", Array As String(SMSstr),"_id")

    Log("Number of columns = " & crsr.ColumnCount)
    Log("Number of SMS = " & crsr.RowCount)
    crsr.Position = 0
    For r = 0 To crsr.RowCount -1
        crsr.Position = r
        Msgid = crsr.GetInt("_id")
        MsgDt = crsr.GetLong("date")
        MsgFrom = crsr.GetString("address")
        MsgBody = crsr.GetString("body")
        SMSList.Add (Msgid& "!"&MsgDt&"!"&MsgFrom&"!"&MsgBody)
    Next
    crsr.Close
    Return SMSList
End Sub

and secondly how to run this in faster way .. It is reading sms very slow .. Do we have any index column which can be used and if yes how ?
 

atulindore

Member
Licensed User
Longtime User
Thank .. Working great with date condition ..

B4X:
    Dim crsr As Cursor = cr.Query(ur,Array As String("_id","date","address","body"),"address = ? AND date >= ?", Array As String(SMSstr,DateTime.Add(DateTime.Now, 0, 0, -7)),"_id")

Any suggestion to improve speed ..
 
Upvote 0
Top