Delphi xe6 读取Android设备联系人


本文整理自网络,侵删。

 和某牛讨论Delphi读Android联系人.写了如下代码
uses
FMX.Helpers.Android,
Androidapi.JNI.JavaTypes, Androidapi.JNI.GraphicsContentViewText,
FMX.Platform.Android, Androidapi.JNIBridge, Androidapi.JNI.Provider,
Androidapi.Helpers;

procedure QueryContact(AName: string; AList: TStrings);
var
cursorContactsPhone: JCursor;
selection: string;
projection: TJavaObjectArray;
FieldIndex: Integer;
begin
if AList <> nil then
AList.Clear;
projection := nil;
if AName.Length > 0 then
begin
projection := TJavaObjectArray.Create(1);
projection.Items[0] := TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME;
selection := JStringToString(TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME)+’ LIKE “%’ + AName + ‘%”‘;
end;

//select projection from 联系人数据库 where selection
cursorContactsPhone := SharedActivity.getContentResolver.query
(TJCommonDataKinds_Phone.JavaClass.CONTENT_URI,
projection {要查询的字段名,nil的全部},
StringToJString(selection){Where条件},
nil { 这里是Where语句的条件参数们,我上面图方便,写死在Where条件中了,没使用参数 } , nil);
if AList <> nil then
while (cursorContactsPhone.moveToNext) do
begin
//获取字段的ColumnIndex
FieldIndex := cursorContactsPhone.getColumnIndex
(TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME);
//读字段内容
AList.Add(JStringToString(cursorContactsPhone.getString(FieldIndex)));
end;
cursorContactsPhone.close;
end;

procedure TForm2.Button1Click(Sender: TObject);
var
s: TStrings;
begin
s := TStringList.Create;
QueryContact(‘王’, s); //查询姓王的人
ShowMessage(s.Text);
s.Free;
end;
我是个懒人,不想再深究了.

对了,别忘了Android有权限,加上读取联系人的权限

 

来源:http://www.raysoftware.cn/?p=501

相关阅读 >>

Delphi关闭程序close,application.terminate与halt区别

Delphi 限制文本框中只接受数字

Delphi 10.3.1 android沉浸式透明状态栏

Delphi读取android设备联系人.Delphixe6中编译通过

Delphi 基础学习指定字符替换其他字符

Delphi win32,win64用于单/多线程计数素数的整数性能比较

Delphi捕捉屏幕

Delphi 更改窗体为顶层窗体不闪烁

Delphi tidhttp+tidssliohandlersocket+ssl

Delphi tdragimage v0.1 Delphi 图片拖拽组件 带有加速度 碰撞效果

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...