views:

219

answers:

4

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  A: 

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

Mark
ive set:<uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
ng93
sorry that I could not help... I hope you solved your problem nowplease let us know where the problem was?
Mark
+1  A: 

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

BezantSoft
My problem was with both the phone contacts and the contacts in my google account. I am not sure with the HTC Eris (Android) 2.1 on the full relevancy of the advice VZW gave me. I did undergo the "remove the apps" protocol, and it did not give me "contact edit" ability improvement to a great degree. Of course, being a FOSS user and developer, I have installed and uninstalled a bunch of applications. This could have something to do with things.
BezantSoft
Last night I did a hard reset on the phone. It was not difficult. I have contacts edit now, and will keep things updated here if problems reoccur.However, the directions on the online PDF (probably v1.5/1.6) don't match the v2.1 phone:
BezantSoft
Manual:To reset the phone1. Press HOME > MENU, then tap Settings > Security > Factory data reset.-----With 2.1, I found: HOME > MENU then SETTINGS > PRIVACY > Factory data resetThen you get the factory reset warning dialog.
BezantSoft
+2  A: 

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

Denis Souza