在一个联系更新只手机的联系号码,当多个号码号码、多个、手机

2023-09-06 11:34:35 作者:一梦蘩华

我在移动,如姓名=ABC一个接触。电话数=123456789TYPE =作品谷歌数=987654321TYPE =工作。现在当我更新一些接触123456789在那个时候第一次获得该联系人的ID,然后更新与phone.type =接触的工作。但问题是,当我更新联系人则洽会更新两个像电话号码,谷歌number.So数量我怎么能只更新手机的联系人号码,但这个ID。我已经写了code如下没有任何其他帐户加入:

 众长的getID(串号){

            开放的我们的uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                    Uri.en code(数));
            光标C = getContentResolver()查询(URI,
                    新的String [] {} PhoneLookup._ID,NULL,NULL,NULL);
            而(c.moveToNext()){
                返回c.getLong(c.getColumnIndex(PhoneLookup._ID));
            }
            返回null;
        }
 公众诠释的GetType(串号){

            开放的我们的uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                    Uri.en code(数));
            光标C = getContentResolver()查询(URI,
                    新的String [] {} PhoneLookup.TYPE,NULL,NULL,NULL);
            而(c.moveToNext()){
            返回c.getInt(c.getColumnIndex(PhoneLookup.TYPE));

            }
            返回0;
        }


龙ID =的getID(delnumber);
INT CONTACT_TYPE =的GetType(delnumber);


 串selectPhone = Data.CONTACT_ID +?=和+ Data.MIMETYPE +='+ Phone.CONTENT_ITEM_TYPE +'+和+ Phone.TYPE +?=;
                                                    Log.i(类型,+ CONTACT_TYPE);
                                                    如果(CONTACT_TYPE == 1)
                                                    {的String [] phoneArgs =新的String [] {将String.valueOf(ID),将String.valueOf(Phone.TYPE_HOME)};
                                                    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
                                                    否则,如果(CONTACT_TYPE == 2)
                                                    {的String [] phoneArgs =新的String [] {将String.valueOf(ID),将String.valueOf(Phone.TYPE_MOBILE)};
                                                    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
                                                    否则,如果(CONTACT_TYPE == 3)
                                                    {的String [] phoneArgs =新的String [] {将String.valueOf(ID),将String.valueOf(Phone.TYPE_WORK)};
                                                    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
                                                    其他
                                                    {的String [] phoneArgs =新的String [] {将String.valueOf(ID),将String.valueOf(Phone.TYPE_MOBILE)};
                                                    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI).withSelection(selectPhone,phoneArgs).withValue(Phone.NUMBER,getnum).build());}
 

解决方案

首先,它很难看到你的格式,你有以上,这可能是为什么没有试图回答这个问题,但是在这里code是$ C $三我用它来更新一个电话号码,而无需更新任何其他电话号码:

 的ArrayList< ContentProviderOperation> OPS =新的ArrayList< ContentProviderOperation>();
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(ContactsContract.Data.CONTACT_ID +=?,新的String [] {}用户id)
            .withSelection(ContactsContract.Data._ID +=?,新的String [] {} phoneId)
            .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.Data.DATA1,phoneNumber的)
            .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,类型)
            .withValue(ContactsContract.CommonDataKinds.Phone.LABEL,标签)
            。建立());

    尝试
    {
        resolver.applyBatch(ContactsContract.AUTHORITY,OPS);
    }
 

关键是要有你想在你的选择查询,更新手机的联系人和手机ID的接触式ID。

iPhone se更新iOS 12正版后有哪些明显的提升和不足

I have one contact in mobile like name="ABC".phone number="123456789" type="work" google number="987654321" type="work".Now when i update the contact of number "123456789" at that time first get the id of that contact and then update the contact with phone.type="work".But the problem is that when i update the contact then the contact will be update in both the number like phone number and google number.So how can i update only the phone's contact number but not any other account joined with this id?.I have written the code as below:

    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());} 

解决方案

First of all its hard to read you code with the formatting you have above, this maybe why no tried to answer this, but here is the code I use to update a phone number without updating any other phone number:

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(ContactsContract.Data.CONTACT_ID + " = ?", new String[] {userId})
            .withSelection(ContactsContract.Data._ID + " = ?", new String[] {phoneId})
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.Data.DATA1, phoneNumber)
            .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, type)
            .withValue(ContactsContract.CommonDataKinds.Phone.LABEL, label)
            .build());

    try 
    {
        resolver.applyBatch(ContactsContract.AUTHORITY, ops);
    } 

The key is to have contact ID of the contact and phone ID of the phone you want to update in your selection for the query.