Do you have an example doing an update ? I keep getting an error while doing

           Uri myPerson = android.provider.Contacts.People.CONTENT_URI;

           Uri myPersonSelected = ContentUris.appendId(myPerson.buildUpon(),
                                       id).build();

            ContentValues values = new ContentValues();
            values.put( android.provider.Contacts.PhonesColumns.NUMBER,
                               "2345");

       // do an update instead
       getContentResolver().update(myPersonSelected,
                          values,
                          null, // where clause
                          null //selection args
          );


       // going for the commit
       managedCursor.commitUpdates();


the error that I'm getting is:

ERROR/Database(544): Error updating number=2345 using UPDATE people
SET number=? WHERE _id=2

- Show quoted text -

On Tue, May 6, 2008 at 12:24 PM, scimitar <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I'm trying to add a contact to the phone contact list, but apparaently
> ContentResolver().insert() is not adding it. (The cursor's count()
> method gives the same result).  My code is sth like this:
>
> Cursor c = getContentResolver().query(
>                        People.CONTENT_URI, null, null, null, null);
>        startManagingCursor(c);
>
>        columns = new String[] {People.NAME};
>        names = new int[] {R.id.row_entry};
>
>        mAdapter =
>                new SimpleCursorAdapter(this, R.layout.main,
>                                c, columns, names);
>        setListAdapter(mAdapter);
>
>        int count = c.count();
>        ContentValues mv = new ContentValues();
>        mv.put(People.NAME, "foo");
>        mv.put(People.NUMBER, "54547");
>        getContentResolver().insert(People.CONTENT_URI, mv);
>        getContentResolver().notifyChange(People.CONTENT_URI, null);
>        c.requery();
>        int ccount = c.count();
>
>
> 'count' and 'ccount' are giving me the same values. Why is this?
>
> thanks,
> >
>

On Tue, May 6, 2008 at 1:29 PM, sacoskun <[EMAIL PROTECTED]> wrote:
>
> Hello scimitar,
>
> People.NUMBER is in android.provider.Contacts.PhonesColumns, not in
> String android.provider.Contacts.PeopleColumns. Therefore you need to
> insert the people table first with the name and get its _id from the
> insert method's returned URI.
>
> Uri myUri = getContentResolver().insert(People.CONTENT_URI, mv);
> String newlyInsertedId  = myUri.getLastPathSegment();
>
> By the help of the newlyInsertedId, insert a phone tuple with the
> number into the phones table by the help of content provider.
>
> Best wishes,
> -sacoskun
>
> On May 6, 1:24 pm, scimitar <[EMAIL PROTECTED]> wrote:
>> Hi,
>> I'm trying to add a contact to the phone contact list, but apparaently
>> ContentResolver().insert() is not adding it. (The cursor's count()
>> method gives the same result).  My code is sth like this:
>>
>> Cursor c = getContentResolver().query(
>>                         People.CONTENT_URI, null, null, null, null);
>>         startManagingCursor(c);
>>
>>         columns = new String[] {People.NAME};
>>         names = new int[] {R.id.row_entry};
>>
>>         mAdapter =
>>                 new SimpleCursorAdapter(this, R.layout.main,
>>                                 c, columns, names);
>>         setListAdapter(mAdapter);
>>
>>         int count = c.count();
>>         ContentValues mv = new ContentValues();
>>         mv.put(People.NAME, "foo");
>>         mv.put(People.NUMBER, "54547");
>>         getContentResolver().insert(People.CONTENT_URI, mv);
>>         getContentResolver().notifyChange(People.CONTENT_URI, null);
>>         c.requery();
>>         int ccount = c.count();
>>
>> 'count' and 'ccount' are giving me the same values. Why is this?
>>
>> thanks,
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [EMAIL PROTECTED]
> Announcing the new M5 SDK!
> http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to