本文介绍了如何使用Android的更新联系电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习的机器人。我想以编程方式upadate联系电话。任何人都可以帮助我,我请了如何能做到这一点。

我的努力是:

 字符串lNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

ContentValues​​值=新ContentValues​​();

乌里lPhoneUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,ContactsContract.CommonDataKinds.Phone.NUMBER);

values​​.put(ContactsContract.CommonDataKinds.Phone.NUMBER,45323333));
。getContentResover()更新(lPhoneUri,价值观,ContactsContract.CommonDataKinds.Phone.NUMBER +=?,新的String [] {lNumber});
 

解决方案

我觉得你是pretty的多有。下面使用新的API来更新联系人的工作电话号码,假设该联系人已经有一个工作电话号码。

 公共无效updateContact(字符串的ContactID,字符串newNumber,活动行为)
    将抛出RemoteException,OperationApplicationException {

        // ASSERT:@contactId alreay有一个工作电话号码
        ArrayList的< ContentProviderOperation> OPS =新的ArrayList< ContentProviderOperation>();
        字符串selectPhone = Data.CONTACT_ID +=?AND+ Data.MIMETYPE +=+
                        Phone.CONTENT_ITEM_TYPE +'+和+ Phone.TYPE +=?;
        的String [] phoneArgs =新的String [] {的ContactID,将String.valueOf(Phone.TYPE_WORK)};
        ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
                .withSelection(selectPhone,phoneArgs)
                .withValue(Phone.NUMBER,newNumber)
                。建立());
        。act.getContentResolver()applyBatch(ContactsContract.AUTHORITY,OPS);
    }
 

I am learning android. I am trying to upadate contact number programmatically. Could anyone help me please how can I do that.

My effort is:

String lNumber = pCur.getString( pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));   

ContentValues values = new ContentValues();

Uri lPhoneUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, ContactsContract.CommonDataKinds.Phone.NUMBER);                      

values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "45323333"));
getContentResover().update(lPhoneUri, values, ContactsContract.CommonDataKinds.Phone.NUMBER+"=?", new String[] { lNumber });        
解决方案

I think you are pretty much there. The following uses the new API to update the WORK phone number of a contact, assume that that contact already has a work phone number.

public void updateContact (String contactId, String newNumber, Activity act) 
    throws RemoteException, OperationApplicationException{

        //ASSERT: @contactId alreay has a work phone number 
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
        String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + 
                        Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Phone.TYPE + "=?";
        String[] phoneArgs = new String[]{contactId, String.valueOf(Phone.TYPE_WORK)}; 
        ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
                .withSelection(selectPhone, phoneArgs)
                .withValue(Phone.NUMBER, newNumber)
                .build()); 
        act.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    }

这篇关于如何使用Android的更新联系电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:12