How can I retrieve recently used contacts in android?

前端 未结 2 1771
萌比男神i
萌比男神i 2021-01-03 07:22

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

2条回答
  •  一生所求
    2021-01-03 07:28

    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:

    
    

提交回复
热议问题