On the internet feel a man write code XE6 under the directory, but get XE7 can not use, because Tjavaobjectarray become generic, get a half-day did not understand tjavaobjectarray how to use, always wrong, But after studying the source code under Androidapi.JNI.Provider and discovering several functions of manipulating the Android database, sit down and record
Here is the code that I modified to get to the database user:
usesFMX. Helpers.android,androidapi.jni.javatypes, ANDROIDAPI.JNI.GRAPHICSCONTENTVIEWTEXT,FMX. Platform.android, Androidapi.jnibridge, androidapi.jni.provider,androidapi.helpers;procedureQuerycontact (AName:string; alist:tstrings);varcursorcontactsphone:jcursor;selection:string;p Rojection:tjavaobjectarray<JString> ; Fieldindex:integer;begin//if alist <> nil Then//alist.clear;//projection: = nil;//if aname.length > 0 Then//begin////projection: = tjavaobjectarray.create (1);////showmessage (inttostr (projection. Length));//ShowMessage (jstringtostring (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME));//Exit;//////projection. Items[0]: = TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME;//Exit;//Selection: = Jstringtostring (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME) + ' like '% ' + AName + '% ';//end;////Exit;Selection: = jstringtostring (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME) +'Like "%'+ AName +'%"';//Select projection from contact database where selectionCursorcontactsphone: =SharedActivity.getContentResolver.query (TJCommonDataKinds_Phone.JavaClass.CONTENT_URI,Nil{projection {The name of the field to query, nil all}, stringtojstring (selection){Where Condition},Nil {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},Nil);ifAlist <>Nil Then while(Cursorcontactsphone.movetonext) Dobegin//get the columnindex of a fieldFieldindex: =Cursorcontactsphone.getcolumnindex (TJContacts_PeopleColumns.JavaClass.DISPLAY_NAME);//Read Field contentsAlist.add (jstringtostring (cursorcontactsphone.getstring (Fieldindex)));End; cursorcontactsphone.close;End;procedureTform1.btn1click (sender:tobject);vars:tstrings;beginS:=tstringlist.create; Querycontact ('Wang', s);//the man who queried Wang's nameShowMessage (s.text); s.free;End;
In addition found:
function cdecl // Modify Database Records function Delete cdecl; // Delete database records
Is it possible to modify the contact, SMS, phone records, etc.? Waiting to be verified ...
About the Android under the Delphi XE7 get Address Book problem