|
|
|
@ -87,17 +87,7 @@ class SystemFunctionHandler(private val context: Context? = null) { |
|
|
|
description = "获取用户通信录联系人列表", |
|
|
|
parameters = mapOf( |
|
|
|
"type" to "object", |
|
|
|
"properties" to mapOf( |
|
|
|
"limit" to mapOf( |
|
|
|
"type" to "integer", |
|
|
|
"description" to "返回联系人数量限制,默认20个", |
|
|
|
"default" to 20 |
|
|
|
), |
|
|
|
"search" to mapOf( |
|
|
|
"type" to "string", |
|
|
|
"description" to "搜索关键词,可选参数" |
|
|
|
) |
|
|
|
), |
|
|
|
"properties" to emptyMap<String, Any>(), |
|
|
|
"required" to emptyList<String>() |
|
|
|
), |
|
|
|
handler = GetContactsListHandler(context) |
|
|
|
@ -1378,10 +1368,7 @@ private class GetContactsListHandler(private val context: Context?) : FunctionHa |
|
|
|
} |
|
|
|
|
|
|
|
return try { |
|
|
|
val limit = (arguments["limit"] as? Number)?.toInt() ?: 20 |
|
|
|
val searchKeyword = arguments["search"] as? String |
|
|
|
|
|
|
|
val contacts = getContactsList(context, limit, searchKeyword) |
|
|
|
val contacts = getContactsList(context) |
|
|
|
|
|
|
|
JSONObject().apply { |
|
|
|
put("result", "成功获取联系人列表") |
|
|
|
@ -1406,7 +1393,7 @@ private class GetContactsListHandler(private val context: Context?) : FunctionHa |
|
|
|
* @param searchKeyword 搜索关键词 |
|
|
|
* @return 联系人列表 |
|
|
|
*/ |
|
|
|
private fun getContactsList(context: Context, limit: Int, searchKeyword: String?): List<Map<String, String>> { |
|
|
|
private fun getContactsList(context: Context): List<Map<String, String>> { |
|
|
|
val contacts = mutableListOf<Map<String, String>>() |
|
|
|
|
|
|
|
try { |
|
|
|
@ -1433,7 +1420,7 @@ private class GetContactsListHandler(private val context: Context?) : FunctionHa |
|
|
|
val nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME) |
|
|
|
val hasPhoneColumn = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER) |
|
|
|
|
|
|
|
while (cursor.moveToNext() && contacts.size < limit) { |
|
|
|
while (cursor.moveToNext()) { |
|
|
|
val contactId = cursor.getString(idColumn) |
|
|
|
val displayName = cursor.getString(nameColumn) ?: "未知联系人" |
|
|
|
val hasPhoneNumber = cursor.getInt(hasPhoneColumn) > 0 |
|
|
|
|