android edit contact

孤者浪人 提交于 2019-11-30 23:52:05

问题


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


回答1:


http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/1/

http://developer.android.com/resources/samples/ContactManager/src/com/example/android/contactmanager/ContactAdder.html

check this both link it will help :)




回答2:


Insert into Data.CONTENT_URI instead of Phone.CONTENT_URI also insert the Data.MIMETYPE column with Phone.CONTENT_ITEM_TYPE.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/3171482/android-edit-contact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!