Android : Get RAW_CONTACT_ID of two contacts having same CONTACT_ID

on Monday, September 22, 2014


I am developing an application in which I am working on Android contacts. i am fetching the details of all contacts as :



private void readContactsFromDevice(){
Cursor contactCursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1", null,"UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");

if(contactCursor.getCount()>0 && contactCursor!=null){
if(contactCursor.moveToFirst()){
do {
String id = contactCursor.getString(contactCursor.getColumnIndex(BaseColumns._ID));
String phone = "";
String[] symbols = { "#", "*" };

if (Integer.parseInt(contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = getContentResolver().query(Phone.CONTENT_URI,null, Phone.CONTACT_ID + " = ?", new String[] { id },null);
if(pCur.getCount()>0 && pCur!=null){
if(pCur.moveToFirst()){
do {
phone = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));
if(phone.length()>9 && phone.length()<15){
String whereName = ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?";
String[] whereNameParams = new String[] { phone };
Cursor nameCur = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, null);
String contactid = null,name = null,number,rawid = null;
if(nameCur.moveToFirst()){
do {
contactid = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
name = nameCur.getString(nameCur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))
number = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
rawid=nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID));
} while (nameCur.moveToNext());
}
}
nameCur.close();
Log.d("Name and No and RawID and ContactID", name+"-"+phone+"-"+rawid+"-"+contactid);
}
} while (pCur.moveToNext());
pCur.close();
}
}
}
}
}while (contactCursor.moveToNext());
}
}
}


What i know is that every contact number is having a unique RAW_CONTACT_ID, by which the contact can be identify.


The issue is : As i am having a contact for example xyz having two number as "1234567890" and "9876543210". When i am fetching details of that contact i am getting the Same name as expected with two different number and CONTACT_ID, but with same RAW_CONTACT_ID which is not expected.


The RAW_CONTACT_ID should not be same. Am i on wrong path, or i done the wrong code?


Please suggest me with your valuable experience.


0 comments:

Post a Comment