0

I am using the following code. In my app user can choose from contacts to view there contact info (app jumps to the respective contact info). This is the result of the code: User clicks on someone whose data was in the phone: app jumps to the contact info User clicks on someone whose data was imported from facebook: if this is the first run of the app, it force closes. If user had previously clicked on someone whose data had been in the phone (added manually), it shows his/her contact info.

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) 
{
  while (cur.moveToNext()) {
  id_contact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                                    name_contact =     
  cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
  if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) 
  {
    if (name_contact.equals(myArr2_cs[item]))
    {
      Toast.makeText(getApplicationContext(), "NAME2: " + name_contact,   Toast.LENGTH_SHORT).show();
      Toast.makeText(getApplicationContext(), "ID2: " + id_contact, Toast.LENGTH_SHORT).show();
      if (Integer.parseInt(cur.getString(
       cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) 
       {
         Cursor pCur = cr.query(
         ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
         ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id_contact}, null);
         id_contact2 = id_contact;
        }
     }
   }
 }
Toast.makeText(getApplicationContext(), "id_contact: " + id_contact2, Toast.LENGTH_SHORT).show();
    Intent intent_contacts = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/" + id_contact2));
      startActivity(intent_contacts);
        }

Here i found that accessing facebook contacts is permitted. The guy also says that "I fetch an cache all contact names/id mappings via FB Graph api (http://graph.facebook.com/me/friends) and use that for the id lookup.". What does that mean?

If i cannot resolve this issue, my program looks lame. 500 contacts appear in the app but the app jumps only in case of around 40 to the contact info. In the last 460 cases it's not working.

Community
  • 1
  • 1
erdomester
  • 11,789
  • 32
  • 132
  • 234
  • The question is not very clear. Are you showing a contact list from the Androd Phone's contacts, or from facebook contacts? – Arcantos May 25 '11 at 18:06

1 Answers1

0

I managed to solve this problem. It turned out the query included only those who has phone number, but my list included everyone. This is why the run resulted in force close and false results. I had to remove those two lines with HAS_PHONE_NUMBER and everything is working fine.

erdomester
  • 11,789
  • 32
  • 132
  • 234