Hi Shay, brelto85,
I am trying to help you so I tried to implement the codes said above in B4A.
The following codes successfully update a message from "Unread" to "Read".
I know my codes are not yet clean, but I don't have much time...
To find a message Id, you need to use Phone library:
(Note. Adapt it as per your need, or you may want to use the SmsInterceptor. In my case, I use an Unread message that is EXISTING in the Inbox to test)
This sub is finding out the message Id among the ones in the last 30 days.
Sub FindSmsId(MessageAddress as String) As Long
Dim messageId As Long
Dim SmsMessages1 As SmsMessages
Dim smsList As List
smsList.Initialize
Dim mySms As Sms
smsList = SmsMessages1.GetAllSince(DateTime.add(DateTime.Now, 0, 0, -30))
If smsList.Size > 0 Then
For i = 0 To smsList.Size - 1
mySms = smsList.Get(i)
If mySms.Address = MessageAddress Then
messageId = mySms.Id
Return messageId
End If
Next
End If
End Sub
With the message Id then you can change it to "READ" (or vice versa) with the following function - do not forget to add permission in your Manifest editor - using ContentResolver library:
Sub MarkSmsAsRead(messageId As Long)
Dim u As Uri
u.Parse("content://sms/")
Dim crsr As Cursor = cr.Query(u, Array As String("_id"), "_id = ?", Array As String(messageId), "")
If crsr.RowCount = 0 Then
Log("No match found: " & messageId)
Else
crsr.Position = 0
Dim cv As ContentValues
cv.Initialize
cv.PutBoolean("read", True)
cr.Update(u, cv, "_id = " & messageId,Null)
End If
crsr.Close
End Sub
It works 100% in my case. Test it and update us.
Edit:
Note. The codes above cannot help you to clear the Unread message notification in the Notification bar. It will still stay there.