Android Instance-read device contact (xe8+ Xiaomi 2)

Source: Internet
Author: User

Related information:

Http://www.colabug.com/thread-1071065-1-1.html

Results:

1. Turn the permissions on read contacts set to True, otherwise report the error to figure one.

2. Search empty no problem, but search the name of the Times wrong, accounted for not tracking, which big God know m I, thank you.

Instance code:

1 UnitUnit1;2 3 Interface4 5 uses6 system.sysutils, System.types, System.uitypes, system.classes, System.variants,7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, FMX. Scrollbox,8 FMX. Memo, Fmx.stdctrls, FMX. Controls.presentation, FMX. Edit, FMX. Layouts;9 Ten type OneTForm1 =class(Tform) A Button1:tbutton; - Label1:tlabel; - Memo1:tmemo; the layout1:tlayout; - Label2:tlabel; - Edit1:tedit; -     procedureButton1Click (sender:tobject); +   Private -     {Private Declarations} +    Public A     {Public Declarations} at   End; -  - var - Form1:tform1; -  - Implementation in uses -FMX. Helpers.android,//need to introduce toAndroidapi.JNI.JavaTypes,//need to introduce +Androidapi.JNI.GraphicsContentViewText,//need to introduce -FMX. Platform.android,//need to introduce theAndroidapi.jnibridge,//need to introduce *Androidapi.JNI.Provider,//need to introduce $Androidapi.helpers;//need to introducePanax Notoginseng  - {$R *.FMX} the {$R *. NMXHDPIPH.FMX ANDROID} + //define a Query method A procedureQuerycontact (AName:string; alist:tstrings); the var + Cursorcontactsphone:jcursor; -Selectionstring; $Oprojection:tjavaobjectarray<jstring>; $Oselectionargs:tjavaobjectarray<jstring>; - Fieldindex:integer; - begin the   ifAlist <>Nil  Then - alist.clear;WuyiOprojection: =Nil; theOselectionargs: =Nil; -   ifAname.length >0  Then Wu   begin -Oprojection: = Tjavaobjectarray<jstring>.Create(1); AboutOselectionargs: = Tjavaobjectarray<jstring>.Create(1); $Oprojection. items[0] :=TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME; -Selection: = jstringtostring (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME) +'Like "%'+ AName +'% "'; -   End; -   //Select projection from contact database where selection ACursorcontactsphone: =SharedActivity.getContentResolver.query + (TJCommonDataKinds_Phone.JavaClass.CONTENT_URI, theOprojection,{the name of the field to query, nil all} -Stringtojstring (selection),{Where Condition} $Oselectionargs,{here is the condition parameter of the where statement, which is convenient for me, I wrote dead in the Where condition, no parameters were used} theStringtojstring ("')); the  the   ifAlist <>Nil  Then the    while(Cursorcontactsphone.movetonext) Do -   begin in     //get the columnindex of a field theFieldindex: =Cursorcontactsphone.getcolumnindex the (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME); About     //Read Field contents the Alist.add (jstringtostring (cursorcontactsphone.getstring (Fieldindex))); the   End; the Cursorcontactsphone.close; + End; -  the //Invoke Query MethodBayi procedureTform1.button1click (sender:tobject); the var the s:tstrings; - begin -S: = Tstringlist.Create; theQuerycontact (Edit1.text, s);//the man who queried Wang's name theMemo1.text: =S.text; the S.free; the End; -  the End.

Android Instance-read device contact (xe8+ Xiaomi 2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.