我有一個聯繫人在移動像名稱=「ABC」。 phone number =「123456789」type =「work」google number =「987654321」type =「work」。現在,當我更新號碼「123456789」的聯繫人時,首先獲取該聯繫人的ID,然後更新與phone.type =「工作」的聯繫人。但問題是,當我更新的聯繫人,然後聯繫人將更新的數字,如電話號碼和谷歌number.So如何更新只有手機的聯繫號碼,但沒有任何其他帳戶與此ID加入。我寫的代碼如下:?當多個號碼在一個聯繫人下更新唯一的手機聯繫號碼聯繫人
public Long getID(String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
Cursor c = getContentResolver().query(uri,
new String[] { PhoneLookup._ID}, null, null, null);
while (c.moveToNext()) {
return c.getLong(c.getColumnIndex(PhoneLookup._ID));
}
return null;
}
public int gettype(String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
Cursor c = getContentResolver().query(uri,
new String[] { PhoneLookup.TYPE }, null, null, null);
while (c.moveToNext()) {
return c.getInt(c.getColumnIndex(PhoneLookup.TYPE));
}
return 0;
}
Long id = getID(delnumber);
int contact_type= gettype(delnumber);
String selectPhone = Data.CONTACT_ID+ "=? AND " + Data.MIMETYPE+ "='"+ Phone.CONTENT_ITEM_TYPE+ "'" + " AND " + Phone.TYPE + "=?";
Log.i("type",""+contact_type);
if(contact_type==1)
{String[] phoneArgs = new String[] {String.valueOf(id), String.valueOf(Phone.TYPE_HOME)};
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
else if(contact_type==2)
{String[] phoneArgs = new String[] {String.valueOf(id), String.valueOf(Phone.TYPE_MOBILE)};
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
else if(contact_type==3)
{String[] phoneArgs = new String[] {String.valueOf(id), String.valueOf(Phone.TYPE_WORK)};
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
else
{String[] phoneArgs = new String[] {String.valueOf(id), String.valueOf(Phone.TYPE_MOBILE)};
ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
您是否找到了解決方案?如果你發現你可以發佈它?感謝 – nikmin