I had this demo built to access the native Android contacts information. It accesses the name, phone number, and email address of all of the contacts in the user’s contacts list. Make sure that you set the contacts Read permission in the Android Manifest like so:
<uses-permission android:name="android.permission.READ_CONTACTS" />
Be sure to check out our demo on how to read the IOS contacts from an IOS device as well. If you implement both demos in your own app you will have a true cross platform Firemonkey application. The API for reading the contacts is it’s own non visual component so you should be able to easily incorporate it into your own application.
Download Delphi XE5 Firemonkey Android Contacts Manager Demo
you did great work, thank you!
I took your code for Android and iOS and built from it one library that works at both mobiles.
If you are interested, please download it from http://pjstrnad.com/files/ContactsManager.zip.
Here is short blog about it: https://pjstrnad.com/accessing-contacts-delphi-ios-android/
I have to tried your unique library for the both mobiles in XE7 on android mobile and i just have a black screem. However the demo for access android work fine, have you and idea about the problem? So i can not found the last link about short blog.
I got this to work in XE5, but now I’m in XE6 and it’s giving me trouble. In the ContactsManager, it doesn’t like any of the StringToJString or JStringToString references. It also gave me this error
“[DCC Error] ContactsManager.pas(132): E2250 There is no overloaded version of ‘query’ that can be called with these arguments”
for this code
“wCursor :=query(wUri,nil, nil,nil, StringToJString(‘display_name ASC’)); // Query to get all contact sorted by display name”
Is there something I’m missing that’s different in XE6?
Is Androidapi.Helpers in your uses clause? It is the new unit that contains those functions in XE6.
That did the trick. I missed that one. Thanks for your help sir.
I want to edit the contacts on Android using XE6, but how???
I tried to use JNI but JContentValues does not init on mobile! it gives an error!
I try it with XE7 and i am satisfied; good job
How do I edit a contact?
Hi, am tried it with XE8 and it worked but it takes 2mins to display contacts on Android. Any way out of this for it to display in shorter time or what may be the problem.
How many contacts are there? The demo looks like it uses the OnCreate even but you probably should not put code in there (the app will load faster). What you could do is load the contacts into a TStringList, TObjectList, or TMemTable and then use the data from that to display in your Delphi control. I’m using that the loading into the visual display may be where the slow down is unless you have 5000 contacts or something. It’s accessing the Android API so if it’s slow from Android itself not sure there is much you can do besides caching the data.