问题
I am adding new contacts as follows:-
ContentValues values = new ContentValues();
String accountType = "test@gmail.com";
values.put(RawContacts.ACCOUNT_TYPE, accountType );
String accountName = "com.google";
values.put(RawContacts.ACCOUNT_NAME, accountName );
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
//Add contact number
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, "123456789");
getContentResolver().insert(Data.CONTENT_URI, values);
//Type of phone number
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.TYPE, Phone.TYPE_WORK);
getContentResolver().insert(Data.CONTENT_URI, values);
//Add contact name
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(Data.DISPLAY_NAME, "First Second");
getContentResolver().insert(Data.CONTENT_URI, values);
Query runs successfully. But the added contacts are not visible in Android Emulator Contacts. Please help. Am I missing anything here.
来源:https://stackoverflow.com/questions/4502787/newly-added-contacts-not-visible-in-android-emulator-contacts