mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 09:27:41 +08:00
优化:提高主动控制·客户端远程查通话、远程查话簿兼容性(兼容鸿蒙2.0)
This commit is contained in:
parent
fcf2876e58
commit
36030bb77b
@ -8,7 +8,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
|
||||||
import android.provider.CallLog
|
import android.provider.CallLog
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@ -173,41 +172,18 @@ class PhoneUtils private constructor() {
|
|||||||
Log.d(TAG, "selection = $selection")
|
Log.d(TAG, "selection = $selection")
|
||||||
Log.d(TAG, "selectionArgs = $selectionArgs")
|
Log.d(TAG, "selectionArgs = $selectionArgs")
|
||||||
|
|
||||||
// 避免超过总数后循环取出
|
//为了兼容性这里全部取出后手动分页
|
||||||
val cursorTotal = Core.app.contentResolver.query(
|
val cursor = Core.app.contentResolver.query(
|
||||||
CallLog.Calls.CONTENT_URI,
|
CallLog.Calls.CONTENT_URI,
|
||||||
null,
|
null,
|
||||||
selection,
|
selection,
|
||||||
selectionArgs.toTypedArray(),
|
selectionArgs.toTypedArray(),
|
||||||
CallLog.Calls.DEFAULT_SORT_ORDER
|
CallLog.Calls.DEFAULT_SORT_ORDER // + " limit $limit offset $offset"
|
||||||
) ?: return callInfoList
|
) ?: return callInfoList
|
||||||
if (offset >= cursorTotal.count) return callInfoList
|
|
||||||
|
|
||||||
val cursor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
Core.app.contentResolver.query(
|
|
||||||
CallLog.Calls.CONTENT_URI,
|
|
||||||
null,
|
|
||||||
Bundle().apply {
|
|
||||||
putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection)
|
|
||||||
putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs.toTypedArray())
|
|
||||||
putStringArray(ContentResolver.QUERY_ARG_SORT_COLUMNS, arrayOf(CallLog.Calls.DATE))
|
|
||||||
putInt(ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING)
|
|
||||||
putInt(ContentResolver.QUERY_ARG_LIMIT, limit)
|
|
||||||
putInt(ContentResolver.QUERY_ARG_OFFSET, offset)
|
|
||||||
},
|
|
||||||
null)
|
|
||||||
} else {
|
|
||||||
Core.app.contentResolver.query(
|
|
||||||
CallLog.Calls.CONTENT_URI,
|
|
||||||
null,
|
|
||||||
selection,
|
|
||||||
selectionArgs.toTypedArray(),
|
|
||||||
CallLog.Calls.DEFAULT_SORT_ORDER + " limit $limit offset $offset"
|
|
||||||
)
|
|
||||||
} ?: return callInfoList
|
|
||||||
|
|
||||||
Log.i(TAG, "cursor count:" + cursor.count)
|
Log.i(TAG, "cursor count:" + cursor.count)
|
||||||
if (cursor.count == 0) return callInfoList
|
|
||||||
|
// 避免超过总数后循环取出
|
||||||
|
if (cursor.count == 0 || offset >= cursor.count) return callInfoList
|
||||||
|
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
val indexName = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)
|
val indexName = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)
|
||||||
@ -225,7 +201,9 @@ class PhoneUtils private constructor() {
|
|||||||
) {
|
) {
|
||||||
indexSimId = cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)
|
indexSimId = cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)
|
||||||
}
|
}
|
||||||
|
var curOffset = 0
|
||||||
do {
|
do {
|
||||||
|
if (curOffset >= offset) {
|
||||||
val callInfo = CallInfo(
|
val callInfo = CallInfo(
|
||||||
cursor.getString(indexName) ?: "", //姓名
|
cursor.getString(indexName) ?: "", //姓名
|
||||||
cursor.getString(indexNumber) ?: "", //号码
|
cursor.getString(indexNumber) ?: "", //号码
|
||||||
@ -237,6 +215,13 @@ class PhoneUtils private constructor() {
|
|||||||
)
|
)
|
||||||
Log.d(TAG, callInfo.toString())
|
Log.d(TAG, callInfo.toString())
|
||||||
callInfoList.add(callInfo)
|
callInfoList.add(callInfo)
|
||||||
|
if (limit == 1) {
|
||||||
|
cursor.close()
|
||||||
|
return callInfoList
|
||||||
|
}
|
||||||
|
}
|
||||||
|
curOffset++
|
||||||
|
if (curOffset >= offset + limit) break
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
if (!cursor.isClosed) cursor.close()
|
if (!cursor.isClosed) cursor.close()
|
||||||
}
|
}
|
||||||
@ -273,41 +258,17 @@ class PhoneUtils private constructor() {
|
|||||||
Log.d(TAG, "selection = $selection")
|
Log.d(TAG, "selection = $selection")
|
||||||
Log.d(TAG, "selectionArgs = $selectionArgs")
|
Log.d(TAG, "selectionArgs = $selectionArgs")
|
||||||
|
|
||||||
// 避免超过总数后循环取出
|
val cursor = Core.app.contentResolver.query(
|
||||||
val cursorTotal = Core.app.contentResolver.query(
|
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||||
null,
|
null,
|
||||||
selection,
|
selection,
|
||||||
selectionArgs.toTypedArray(),
|
selectionArgs.toTypedArray(),
|
||||||
ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY
|
ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY
|
||||||
) ?: return contactInfoList
|
) ?: return contactInfoList
|
||||||
if (offset >= cursorTotal.count) return contactInfoList
|
|
||||||
|
|
||||||
val cursor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
Core.app.contentResolver.query(
|
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
||||||
null,
|
|
||||||
Bundle().apply {
|
|
||||||
putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection)
|
|
||||||
putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs.toTypedArray())
|
|
||||||
putStringArray(ContentResolver.QUERY_ARG_SORT_COLUMNS, arrayOf(ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY))
|
|
||||||
putInt(ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_ASCENDING)
|
|
||||||
putInt(ContentResolver.QUERY_ARG_LIMIT, limit)
|
|
||||||
putInt(ContentResolver.QUERY_ARG_OFFSET, offset)
|
|
||||||
},
|
|
||||||
null)
|
|
||||||
} else {
|
|
||||||
Core.app.contentResolver.query(
|
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
||||||
null,
|
|
||||||
selection,
|
|
||||||
selectionArgs.toTypedArray(),
|
|
||||||
ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY + " limit $limit offset $offset"
|
|
||||||
)
|
|
||||||
} ?: return contactInfoList
|
|
||||||
|
|
||||||
Log.i(TAG, "cursor count:" + cursor.count)
|
Log.i(TAG, "cursor count:" + cursor.count)
|
||||||
if (cursor.count == 0) return contactInfoList
|
|
||||||
|
// 避免超过总数后循环取出
|
||||||
|
if (cursor.count == 0 || offset >= cursor.count) return contactInfoList
|
||||||
|
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
val displayNameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)
|
val displayNameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)
|
||||||
@ -319,6 +280,10 @@ class PhoneUtils private constructor() {
|
|||||||
)
|
)
|
||||||
Log.d(TAG, contactInfo.toString())
|
Log.d(TAG, contactInfo.toString())
|
||||||
contactInfoList.add(contactInfo)
|
contactInfoList.add(contactInfo)
|
||||||
|
if (limit == 1) {
|
||||||
|
cursor.close()
|
||||||
|
return contactInfoList
|
||||||
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
if (!cursor.isClosed) cursor.close()
|
if (!cursor.isClosed) cursor.close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user