0

I 'm trying to read and display contacts from phone book in android. My Device is synced up with gmail and funambol which togehter have more than 600 records. Now by default my application reads gmail contacts. On selecting any contact from the displayed list, it throws an exception as the list is displaying a gmail contact which just has email and no phone no.

I need phone no to use in my application.

thanks

success_anil
  • 3,659
  • 3
  • 27
  • 31

1 Answers1

2

Take a look at this answer here. It provides all the detail you need to get the contacts right.

The reason for the crash might be because you are trying to read the phone number when there is none, causing a NullPointerException. Maybe check if it's null before you try and use it, and if it is null then ask the user to pick again.

If this isn't right, feel free to provide more detail like code and logcat logs.

Community
  • 1
  • 1
matto1990
  • 3,766
  • 2
  • 27
  • 32
  • Ya you are right. the code works fine.. But my phone book is synced with gmail. And this code displays the records from gmail account too along with my phone book's account . – success_anil Aug 23 '10 at 13:08
  • They are the same thing. Contacts is both combined. As far as I'm away there's no way to only get ones which aren't gmail. Maybe do some digging into the API of the new ContactsManager API. Not played with that yet – matto1990 Aug 23 '10 at 19:08
  • Well that was pretty simple.. Just need to invoke with proper content URI.. Thanks. Well I 've to select multiple contacts out of list. then do I 've to proceed using different way – success_anil Aug 30 '10 at 17:11
  • @success_anil Could you please tell us which Content URI fixed your problem? I have a similiar one: I want to query for all phonecontacts, but don't want to have the facebook/gmail-Contacts in the same list. – Christoph Haefner Dec 26 '10 at 10:13