一个联系人ID给出两个相似的数字

时间:2016-08-16 05:31:54

标签: android android-contacts telephonymanager

我从联系人列表中获取了所有联系电话号码,我已经应用了日志来检查值,而且很少有联系人ID给出数字,如

id 22261名称ABC

id 22261号码+91 98765 43210

id 22261号码+919876543210

其他联系人以类似的方式保存,给出正确的回复

我尝试过几次修改,如果我通过电话.NORMALIZED_NUMBER,它解决了上述问题,但它返回的几个联系号码为 null

以下是我的阅读联系人的代码

Cursor cursor_number=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
        if(cursor_number!=null){

            if (cursor_number.moveToFirst()){
                do{
                    contact_id=cursor_number.getString(cursor_number.getColumnIndex(ContactsContract.Contacts._ID));
                    String name=cursor_number.getString(cursor_number.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));


                    if(Integer.parseInt(cursor_number.getString(cursor_number.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))>0){
                        Cursor cursor_number1=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER},
                                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ? ", new String[]{contact_id},null);
                        while (cursor_number1.moveToNext())
                        {
                            String number = cursor_number1.getString(cursor_number1.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
// To add number to an ArrayList
                            details.add(number);
                            }
                        cursor_number1.close();
                    }
                }
                while (cursor_number.moveToNext());
            }
        }
        else{
            Toast.makeText(getApplicationContext(),"NO CONTACTS TO DISPLAY",Toast.LENGTH_LONG).show();
        }
        cursor_number.close();
}

我的代码中有任何错误吗?需要指导,谢谢!

0 个答案:

没有答案