private void insertContact(String serviceName, String serviceNumber)
{ //先插入空值得到rawContactId ,然后用于下面插值
ContentValues values = new ContentValues();
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.GIVEN_NAME, serviceName);
getContentResolver().insert(Data.CONTENT_URI, values);
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, serviceNumber);
values.put(Phone.TYPE,Phone.TYPE_WORK);
getContentResolver().insert(Data.CONTENT_URI, values);
//values.clear();
//values.put(Data.RAW_CONTACT_ID, rawContactId);
//values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
//values.put(Email.DATA,serviceEmail);
//values.put(Email.TYPE,Email.TYPE_WORK );
//getContentResolver().insert(Data.CONTENT_URI, values);...... }
android插入联系人
最新推荐文章于 2024-09-27 23:22:31 发布