我有一个代码,它使用 Content Resolver 从移动联系人中获取电话号码。我在 2 部手机上对其进行了测试。在一个它获取国家代码,而在另一个它没有。有没有办法找出国家代码是否存在于手机号码,如果存在,我想将其与号码分开。这是我的代码。请帮帮我
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if ((cur != null ? cur.getCount() : 0) > 0) {
while (cur != null && cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
phoneContactName.add(name);
if (cur.getInt(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()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
String countryCode = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
phoneContactNos.add(phoneNo);
dup_phoneContactNos.add(phoneNo);
/*if (registeredContactNos.contains(phoneNo)) {
Toast.makeText(getApplicationContext(), "match found", Toast.LENGTH_SHORT).show();
selectedContactName.add(name);
selectedContactNos.add(phoneNo);
populateList(name, phoneNo);
}*/
Log.i(TAG, "Name: " + name);
Log.i(TAG, "Phone Number: " + phoneNo);
}
pCur.close();
}
}
/*for(int i=0;i<selectedContactName.size();i++)
{
Toast.makeText(getApplicationContext(),selectedContactName.get(i)+","+selectedContactNos.get(i),Toast.LENGTH_SHORT).show();
}*/
}
if (cur != null) {
cur.close();
}