Newly added contacts not visible in Android Emulator contacts

微笑、不失礼 提交于 2019-12-11 05:12:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!