diff --git a/app/build.gradle b/app/build.gradle index c58036a0..21f30e97 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.5.16' + implementation 'com.simplemobiletools:commons:4.5.17' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 65956686..4422660d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,8 @@ + + ) -> Unit) { + Thread { + val calls = ArrayList() + if (!activity.hasPermission(PERMISSION_WRITE_CALL_LOG)) { + callback(calls) + return@Thread + } + + val uri = android.provider.CallLog.Calls.CONTENT_URI + val projection = arrayOf( + CallLog.Calls._ID, + CallLog.Calls.NUMBER, + CallLog.Calls.DATE, + CallLog.Calls.DURATION, + CallLog.Calls.CACHED_NAME, + CallLog.Calls.TYPE + ) + + val sorting = "${CallLog.Calls._ID} DESC LIMIT 50" + + var cursor: Cursor? = null + try { + cursor = activity.contentResolver.query(uri, projection, null, null, sorting) + if (cursor?.moveToFirst() == true) { + do { + val id = cursor.getIntValue(CallLog.Calls._ID) + val number = cursor.getStringValue(CallLog.Calls.NUMBER) + val date = cursor.getLongValue(CallLog.Calls.DATE) + val duration = cursor.getIntValue(CallLog.Calls.DURATION) + val name = cursor.getStringValue(CallLog.Calls.CACHED_NAME) ?: "" + val type = cursor.getIntValue(CallLog.Calls.TYPE) + val recentCall = RecentCall(id, number, date, duration, name, type) + calls.add(recentCall) + } while (cursor.moveToNext()) + } + } finally { + cursor?.close() + } + callback(calls) + }.start() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/RecentCall.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/RecentCall.kt new file mode 100644 index 00000000..f2bbfdf5 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/RecentCall.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.contacts.models + +data class RecentCall(var id: Int, var number: String, var date: Long, var duration: Int, var name: String, var type: Int)