-1

I'm having a hellva time just getting the name and phone # from the ContactsContract.Contacts... I realize they updated the API but I'm banging my head against the wall here. I put my code below with the OnClickListener and OnStartActivity... The name comes fine but I can't get the number... Been banging my head for 4 hours on this and searched everywhere. Can someone throw me a bone?

            public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId()){
case R.id.bCallContacts:
             Intent i = new Intent(Intent.ACTION_PICK, 
                     ContactsContract.Contacts.CONTENT_URI); 
                     startActivityForResult(i, PICK_CONTACT); 

            break;  }






 private Cursor getContact(Uri uri) { 
        // Run query 
     Cursor c =  managedQuery(uri, null, null, null, null); 
        return c; 
} 



 @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent 
data) 
    { 
     super.onActivityResult(requestCode, resultCode, data); 
        Cursor c = getContact(data.getData()); 
        if (c.moveToFirst()) 
        { 
            String name = 
c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME) ); 
            callName.setText(name); 
            String phoneNumber = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
                                callNum.setText(phoneNumber); 
        } 


    } 
user961389
  • 423
  • 2
  • 8
  • 19

1 Answers1

0

Will this work? Not my code I found it on another page get contact info from android contact picker

 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}, null);
    while (pCur.moveToNext()) {
    // Do something with phones
    } 
    pCur.close();
}
Community
  • 1
  • 1
error_null_pointer
  • 457
  • 1
  • 6
  • 21