我正在尝试将姓名和电话号码添加到电话簿中。它始终显示“已插入”,但从未出现在电话簿中。
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int index = ops.size();
ops.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, index)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
mDetail.get(position).getName())
.withValue(
ContactsContract.CommonDataKinds.Phone.NUMBER,
mDetail.get(position).getPhone())
.withValue(
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
.build());
try {
getContentResolver().applyBatch(
ContactsContract.AUTHORITY, ops);
Toast.makeText(Detail_Activity.this, "Inserted..",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(Detail_Activity.this, e.getMessage(),
Toast.LENGTH_SHORT).show();
}
建议/帮助将不胜感激