开发者

add a new number to an existing contact on Android 2.2

开发者 https://www.devze.com 2023-03-22 07:28 出处:网络
I am trying to add new numbers (or emails or websites) to an existing contact, but the code does not work well.The code is as followings:

I am trying to add new numbers (or emails or websites) to an existing contact, but the code does not work well. The code is as followings:

int rowId = cursor1.getInt(cursor1
                .getColumnIndex(ContactsContract.RawContacts._ID));
ContentValues contentValues = new ContentValues();
contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rowId);
contentValues.put(ContactsContract.Data.MIMETYPE,
        ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
contentValues.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
        "45435345");
contentValues.put(ContactsContract.CommonDataKinds.Phone.TYPE,
        Phone.TYPE_HOME);

ops.add(ContentProviderOperation
        .newInsert(ContactsContract.Data.CONTENT_URI)
        .withValues(contentValues).build());
开发者_如何转开发

when the codes run ,there is no errors,and there is no changes.I am depressed with it.Any help will save me!!!


Maybe you need these two permissions:

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

Perhaps you need to use ContentResolver instead of ContentValues.


use this code to insert New Contatct in phone Contatcs:

Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse("tel:" + currentNum.getText())); //currentNum is my TextView, you can replace it with the number directly such as Uri.parse("tel:1293827")
intent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true); //skips the dialog box that asks the user to confirm creation of contacts
startActivity(intent);

enjoy your code:)-

0

精彩评论

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