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