简体   繁体   中英

android edit contact

hi im trying to add a phone number to an existing contact on android 2.1. Im currently using:

ContentValues values = new ContentValues();
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null, selection, null,ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
if (cursor.getCount() > 0) {
    cursor.moveToPosition(oldcontactid);
    contactid = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
    values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
    if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{contactid}, null);
        while (pCur.moveToNext()) {
            values.put(Phone.NUMBER,pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        }
        pCur.close();
    }
}
Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values);

but i get an error:

java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones

how would i be able to fix this?

thanks for any help, ng93

插入Data.CONTENT_URI而不是Phone.CONTENT_URI也插入带有Phone.CONTENT_ITEM_TYPEData.MIMETYPE列。

Have you set the correct permissions in the AndroidManifest.xml? As far as I know the access to the personal information (contacts) is restricted by default.

see here for more about the permission system in android

You also might want to check your installed apps vs program memory. My Droid Eris worked fine on contacts and from just about any contacts aware application, too.

Until I went past some point of memory load. VZW support 1st level did me no good, I had to insist on 2nd level support. Finally got an answer from someone who knew his spinach. He told be that I had too many apps on the phone, and that this was a known problem.
Still have not cut my working set down enough to get contact edit working :-(

/s/ BezantSoft

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM