1
我正在尝试使用内容提供者编辑我的手机的联系人。加载数据我已经使用下面的代码,它工作正常。如何使用内容提供者更新现有联系人
private ArrayList<String> getRecords()
{
ArrayList<String> records=new ArrayList<String>();
Cursor cursor=getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
if (cursor.moveToFirst())
{
String name="";
String phone="";
String id="";
do{
id=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));
name =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
phone =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
name = id+" "+name+"\n"+phone;
records.add(name);
}
while(cursor.moveToNext());
}
return records;
}
现在我想编辑实际上想要更改所选联系人的名称。我想下面的代码
Uri uri= ContentUris.withAppendedId(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, id);
ContentValues values=new ContentValues();
values.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "<r XX");
getContentResolver().update(uri, values, null,null);
但它没有更新。我能知道什么?请帮忙。我已经检查了互联网以及其他答案,但没有找到满意的答案。
Uri uri = ContentUris.withAppendedId(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,3625); \t \t ContentValues values = new ContentValues(); (ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,“XX先生”); ();}};}};}};}};}};} 检查此代码。但它不起作用:-( – Asif