Код: Выделить всё
@SuppressLint("Range")
fun fetchSMS(context: Context): List {
val smsList = mutableListOf()
val uri = Uri.parse("content://sms")
val cursor = context.contentResolver.query(
uri,
null,
null,
null,
"date DESC" // Most recent first
)
cursor?.use {
while (it.moveToNext()) {
val id = it.getLong(it.getColumnIndex("_id"))
val address = it.getString(it.getColumnIndex("address")) ?: "Unknown"
val body = it.getString(it.getColumnIndex("body")) ?: ""
val date = it.getLong(it.getColumnIndex("date"))
val type = it.getInt(it.getColumnIndex("type"))
smsList.add(SMSMessage(id, address, body, date, type))
}
}
return smsList
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... sms-app-in