add a new number to an existing contact on Android 2.2
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:)-
精彩评论