I want the list of recently used contacts in my application.
Just like in composing a new message there is a list of recently used contact, how can I access those co
You can use this to go over all phone call logs:
object CallLogHelper {
@RequiresPermission(allOf = arrayOf(Manifest.permission.READ_CONTACTS, permission.READ_CALL_LOG))
@WorkerThread
fun getRecentCallsLogs(context: Context) {
val cursor = context.contentResolver.query(Calls.CONTENT_URI, null, null, null, Calls.DATE + " DESC")
if ((cursor?.count ?: 0) == 0) {
cursor?.close()
return
}
var itemsScannedSoFar = 0
cursor.moveToFirst()
while (!cursor.isAfterLast) {
Log.d("AppLog", "call log:" + DatabaseUtils.dumpCurrentRowToString(cursor))
cursor.moveToNext()
}
cursor.close()
}
}
Manifest: