codingdir logo sitemap sitemap |

Android - use ContactPicker to get a number AND last name?

By : , Category : android

The contact picker returns a URI for the contact requested. You need to requery on this URI and you can get whatever you want.

public void onActivityResult(int reqCode, int resultCode, Intent data) {
  super.onActivityResult(reqCode, resultCode, data);

  switch (reqCode) {
    case (PICK_CONTACT) :
      if (resultCode == Activity.RESULT_OK) {
        Uri contactData = data.getData();
        Cursor c =  getContentResolver().query(contactData, null, null, null, null);
        if (c.moveToFirst()) {
         // TODO Whatever you want to do with the selected contact
ReLated :

Please watch this link i think someone has already done your job

android get contact picture, name, and mobile number

First get contacts from address book and pass them into an NSArray:

CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {

    NSMutableArray *contacts = [NSMutableArray array];

    NSError *fetchError;
    CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];

    BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) {
        [contacts addObject:contact];
    if (!success) {
        NSLog(@"error = %@", fetchError);

Then simply use the NSArray in a UITableView and from there you can customize the font, colors, etc.

I use ContactsContract.PhoneLookup.NORMALIZED_NUMBER when searching a phone number, and this work well. It is a column name error.

I had this behaviour today in my Universal Store App for Win 8.1, so may be this helps you out. I had different exceptions though (FileNotFoundException and just plain System.Exception), so I'm not really certain this is the same issue.

As far as my experiments go, this is what is currently needed to make ContactPicker work:

  • ContactPicker instance must be created in the UI thread
  • contactPicker.DesiredFieldsWithContactFieldType must have exactly one item (0 or >1 items yield exception)

This is what I ended up doing:

// using Windows.ApplicationModel.Core;

// in an async method:
Contact user = null;
AutoResetEvent resetEvent = new AutoResetEvent(false);
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
    (async ()=>{
      ContactPicker contactPicker = new ContactPicker();
      user = await contactPicker.PickContactAsync();
if (user != null) {
    // do smth

Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .