android – 如何在Firemonkey移动应用程序中获取手机的联系人列表?

前端之家收集整理的这篇文章主要介绍了android – 如何在Firemonkey移动应用程序中获取手机的联系人列表?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何在FireMonkey移动应用程序中获取手机的联系人列表?

最佳答案
在这里你去..它没有完成,因为它读取一个人的所有数字,如果有两个数字,你将有两次这个人在列表中列出..但从这里我认为你可以工作,并根据你的需要调整它:) )

function GetContact: TStringList;
var
cursorContacts,cursorContactsPhone: JCursor;
hasPhoneNumber: Integer;
id: Int64;
displayName,phoneNumber,contactID: string;
begin
Result := TStringList.Create;
cursorContacts := SharedActivity.getContentResolver.query(TJContactsContract_Contacts.JavaClass.CONTENT_URI,nil,nil);
if (cursorContacts.getCount > 0) then
begin
while (cursorContacts.moveToNext) do
begin
id := cursorContacts.getLong(cursorContacts.getColumnIndex(StringToJString('_ID')));
displayName := JStringToString(cursorContacts.getString(cursorContacts.getColumnIndex(StringToJString('DISPLAY_NAME'))));
hasPhoneNumber := cursorContacts.getInt(cursorContacts.getColumnIndex(StringToJString('HAS_PHONE_NUMBER')));
if (hasPhoneNumber > 0) then
begin
cursorContactsPhone := SharedActivity.getContentResolver.query(TJCommonDataKinds_Phone.JavaClass.CONTENT_URI,StringToJString('CONTACT_ID = ' + IntToStr(id)),nil);
while (cursorContactsPhone.moveToNext) do
begin
phoneNumber := JStringToString(cursorContactsPhone.getString(cursorContactsPhone.getColumnIndex(StringToJString('DATA1'))));
contactID := JStringToString(cursorContactsPhone.getString(cursorContactsPhone.getColumnIndex(StringToJString('CONTACT_ID'))));
Result.Add(displayName + ': ' + phoneNumber);
end;
cursorContactsPhone.close;
end;
end;
end;
cursorContacts.close;
end;

最好的祝福,
Kruno

原文链接:https://www.f2er.com/android/430959.html

猜你在找的Android相关文章