Issue About Getting Contact In Android
i have Developed an application that have facility of saving Phone Number and getting Contact from Phone Directory but i getting error in my code my code is @Override public voi
Solution 1:
Try this way,hope this will help you to solve your problem.
Note : add read contact permission in AndroidManifest.xml
String id="";
String no="";
String name="";
Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null);
while(cursor.moveToNext()){
id = cursor.getString(cursor.getColumnIndex("_id"));
if("1".equalsIgnoreCase(cursor.getString(cursor.getColumnIndex("has_phone_number")))){
Cursor cursorNo = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, "contact_id = " + id, null, null);
while (cursorNo.moveToNext()) {
if (cursorNo.getInt(cursorNo.getColumnIndex("data2")) == 2){
no = no.concat(cursorNo.getString(cursorNo.getColumnIndex("data1")));
break;
}
}
cursorNo.close();
}
}
cursor.close();
String whereName = ContactsContract.Data.MIMETYPE + " = ? AND " + ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ?";
String[] whereNameParams = new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, id };
Cursor nameCur = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
while (nameCur.moveToNext()) {
name= nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
}
nameCur.close();
Toast.makeText(this," Name : "+name+" No : "+no,Toast.LENGTH_SHORT).show();
Post a Comment for "Issue About Getting Contact In Android"