mark unread SMS as Read on open

This commit is contained in:
tibbi 2020-04-04 20:22:17 +02:00
parent 654359eaea
commit 3ec40cb979
2 changed files with 17 additions and 0 deletions

View file

@ -167,7 +167,19 @@ fun Context.insertNewSMS(address: String, subject: String, body: String, date: L
put(Telephony.Sms.SUBJECT, subject)
put(Telephony.Sms.BODY, body)
put(Telephony.Sms.DATE, date)
put(Telephony.Sms.READ, 0)
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX)
}
contentResolver.insert(uri, contentValues)
}
fun Context.markSMSRead(id: Int) {
val uri = Telephony.Sms.CONTENT_URI
val contentValues = ContentValues().apply {
put(Telephony.Sms.READ, 1)
}
val selection = "${Telephony.Sms._ID} = ? AND ${Telephony.Sms.READ} = ?"
val selectionArgs = arrayOf(id.toString(), "0")
contentResolver.update(uri, contentValues, selection, selectionArgs)
}