开发者

Can`t insert a new record into contacts

I can successfully insert a new record using People.CONTENT_URL according to http://developer.android.com/guide/topics/providers/content-providers.html#addingrecord. But the People class is dep开发者_运维百科recated, So i would like to using ContentProviderOperation and Data.CONTENT_URL to insert record. here is my code.

        super.onCreate(savedInstanceState);
        ArrayList operations = new ArrayList();
        operations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValue(Phone.CONTACT_ID, "23").withValue(CommonDataKinds.Phone.NUMBER,
                        "13412341234123412341234").build());
        try {
            getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OperationApplicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


According to my understanding, you simply want to add a new contact, right?

I have answered the question Here. I have used the same piece of code and it works for me.


If you are trying to add a new contact try this code :

        Intent intent = new Intent(Intent.ACTION_INSERT); 
        intent.setType(ContactsContract.Contacts.CONTENT_TYPE);  
        intent.putExtra(ContactsContract.Intents.Insert.NAME, "name"); 
        intent.putExtra(ContactsContract.Intents.Insert.PHONE, "123456");  
        startActivity(intent);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜