android phone number is null for sim contacts
The following code returns Phone number as null for the contacts in SIM. Whereas for the contacts in Phone, it returns the correct value. Please let me know, whether the URI should be different to read the phone number from SIM. Below is my code, almost a copy from Android Contact tutorial.
long contactId = -1;
// Load the display name for the specified person
Cursor cursor = contentResolver.query(contactUri,new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
try
{
if (cursor.moveToFirst())
{
contactId = cursor.getLong(0);
}
}
finally
{
cursor.close();
}
// Load the phone number (if any).
String phoneNumber=null;
cursor = contentResolver.query(Phone.CONTENT_URI,new String[]{Phone.NUMBER},Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");
try
{
if (cursor.moveToFirst())
{
phoneNumber=cursor.getString(0);
}
开发者_如何转开发 }
finally
{
cursor.close();
}
精彩评论