Unable to Update a Contact Phone number

by Sam » Tue, 24 Feb 2009 11:23:22 GMT


Sponsored Links
 Hi All,

I am currently unable to update an existing contact record's phone
number.   I am able to insert a new phone number to an existing
contact record but unable to delete or modify existing phone number
records of a contact.
Is there a way to either:
- delete an existing phone number from a contact record.
or
- update an existing phone number of a contact record.

The sample code is as shown below:

To delete existing phone numbers of a contact record:
row = getContentResolver().delete(ContentUris.withAppendedId
(Phones.CONTENT_URI, uid),null,null);
                        Log.v(TAG,"row =" + row);

the row value is always 0 even if phone numbers are present. Thus, the
deletion does not take place.

To update a phone number:

Uri PersonUri = ContentUris.withAppendedId(People.CONTENT_URI, uid);
Uri PhoneUri = Uri.withAppendedPath
(PersonUri,People.Phones.CONTENT_DIRECTORY);
ContentValues values = new ContentValues();
values.put(Phones.NUMBER,"1234567890");
values.put(Phones.TYPE,1);
row = getContentResolver().update(PhoneUri,values, null, null);

This throws a unsupported Operation exception.

Kindly guide.

Thanks and Regards,
Sam

--~--~---------~--~----~------------~-------~--~----~



Unable to Update a Contact Phone number

by Sam » Tue, 24 Feb 2009 11:23:31 GMT


 Hi All,

I am currently unable to update an existing contact record's phone
number.   I am able to insert a new phone number to an existing
contact record but unable to delete or modify existing phone number
records of a contact.
Is there a way to either:
- delete an existing phone number from a contact record.
or
- update an existing phone number of a contact record.

The sample code is as shown below:

To delete existing phone numbers of a contact record:
row = getContentResolver().delete(ContentUris.withAppendedId
(Phones.CONTENT_URI, uid),null,null);
                        Log.v(TAG,"row =" + row);

the row value is always 0 even if phone numbers are present. Thus, the
deletion does not take place.

To update a phone number:

Uri PersonUri = ContentUris.withAppendedId(People.CONTENT_URI, uid);
Uri PhoneUri = Uri.withAppendedPath
(PersonUri,People.Phones.CONTENT_DIRECTORY);
ContentValues values = new ContentValues();
values.put(Phones.NUMBER,"1234567890");
values.put(Phones.TYPE,1);
row = getContentResolver().update(PhoneUri,values, null, null);

This throws a unsupported Operation exception.

Kindly guide.

Thanks and Regards,
Sam

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Unable to Update a Contact Phone number

by rex » Wed, 25 Feb 2009 02:03:49 GMT


 I see only the difference from my code (which is working)
DELETE
is that instead of putting Phones.CONTENT_URI put
Contacts.Phones.CONTENT_URI

UPDATE
provide to the update method phoneId, get uri and call update:
phoneUri = ContentUris.withAppendedId(Contacts.Phones.CONTENT_URI,
phoneId);
row = getContentResolver().update(phoneUri,values, null, null);

PS Append Contacts to all Phones entries: Contacts.Phones

ildus

--~--~---------~--~----~------------~-------~--~----~



Unable to Update a Contact Phone number

by Sam » Wed, 25 Feb 2009 06:02:17 GMT


 Hi ildus,

Thanks for the response!

I tried your solutions and the update still does not take place. I get
row = 0 for both delete and update , meaning no rows were updated.
If I can just get one of them to work - either delete or update, it
would be sufficient to me.
So your able to delete existing phone numbers of a contact record and
update existing number type and value right?
I was wondering if you did your test on the emulator or the phone? And
on what version of the SDK.
Kindly let me know.

Thanks,
Sam




--~--~---------~--~----~------------~-------~--~----~



Unable to Update a Contact Phone number

by rex » Wed, 25 Feb 2009 06:21:54 GMT


 Sam,

I think the problem is how you created the contact entry. Try this
method to create contact
replace CallCardProvider object with yours actual parameters. Then try
delete or update this entry using methods above.
Hope it helps.

Ildus
 //Create Contact //
            public long createContactEntry(CallCardProvider ccp) {
                ContentValues values = new ContentValues();
                Uri phoneUri = null;

                values.put(Contacts.People.NAME, mCtx.getText
(R.string.nameStartWith)+" "+ccp.getName());
                //1 = the new contact is added to favorites
                //0 = the new contact is not added to favorites
                values.put(Contacts.People.STARRED,0);
                values.put(People.NOTES, ccp.getPostNumber());

                //Add Phone Numbers
                Uri uri = this.mCtx.getContentResolver().insert
(Contacts.People.CONTENT_URI, values);

                long contactId = Long.parseLong(uri.getLastPathSegment());
                Log.i(TAG,"UriPeople="+uri.toString()+" id created="+contactId);
                phoneUri = Uri.withAppendedPath(uri,
Contacts.People.Phones.CONTENT_DIRECTORY);
                Log.i(TAG, "phoneUri="+phoneUri.toString());
                values.clear();
                values.put(Contacts.Phones.TYPE,
Phones.TYPE_CUSTOM);//.TYPE_MOBILE);
                values.put(Contacts.Phones.LABEL, ccp.getNotes());
                values.put(Contacts.Phones.NUMBER, 
ccp.getNumber());//.split(",")
[0]);
                Uri phone = mCtx.getContentResolver().insert(phoneUri, values);
                long phoneId = Long.parseLong(phone.getLastPathSegment());
                Log.i(TAG, "Phone created="+phone.toString());
                Uri groupMember = Contacts.GroupMembership.CONTENT_URI;
                Uri group = Contacts.Groups.CONTENT_URI;
                Cursor c = mCtx.getContentResolver().query(group, new String[]
{Groups._ID},
                                Groups.NAME+"='"+Groups.GROUP_MY_CONTACTS+"'", 
null, null);
                long groupId = 0;
                if(c.getCount()>0 && c.moveToFirst())
                        groupId = c.getLong(c.getColumnIndex(Groups._ID));
                c.close();
                if(groupId ==0) {
                        Log.e(TAG, "groupId=0 Insert to group is skipped");
                        return phoneId;
                }
                values.clear();
                values.put(Contacts.GroupMembership.PERSON_ID, contactId);
                values.put(Contacts.GroupMembership.GROUP_ID, groupId);
                groupMember = mCtx.getContentResolver().insert(groupMember,
values);
                Log.i(TAG, "groupMemberUri = "+groupMember.toString());
                return phoneId;
            }
--~--~---------~--~----~------------~-------~--~----~



Unable to Update a Contact Phone number

by Sam » Thu, 26 Feb 2009 03:17:06 GMT


 i ildus,

Thanks for the sample! I was able to get update to work and figure out
where we differ.

I was using the personID to do multiple deletes or updates. The logic
was similar to query where we use the Person id to query the phone
database for multiple phone records that are associated with the
Person.
Unfortunately what works for query does not work for update or delete.
For update or delete we have to use the Phone ID to access the single
row in the phone database to delete or update. So now I do a query
using PersonID and get all the phone records for the person. Then I
get each record's PhoneID and use it to update individual rows in the
phone database. This approach works.
Kindly let me know if there is a better approach.

Thanks for all the help.
Sam


On Feb 24, 4:21pm, rex <iha...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Unable to Update a Contact Phone number

by rex » Fri, 27 Feb 2009 22:55:36 GMT


 Hi Sam,

You are talking about batch update? But I don't see the point why you
need to update all phones belong to person in one shot with the same
values?
I would return from method getPerson(long personId) domain object
Person with reference to the List of Phones objects or List of
PhoneIds  and then if need update/delete use specific phoneId from the
list (no need extra call to db to get person)

Ildus
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Motorola Cliq Review

So guys here are the Motorola Cliq Review via Engadget [http://bit.ly/uLXrO]
and via Gizmodo [http://bit.ly/eG8eB]Looks good and a decent replacement for
your G1... :P

tp gw keknya ttp nunggu si Sholes aja ahhh... :P

--~--~---------~--~----~------------~-------~--~----~
Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to id-android@googlegroups.com

To request to subscribe to this group, please visit the following page:
 

2. Kernel Compile Error : error: asm/arch/mm.h

Hi,

Each time I'm trying to compile the kernel (android_msm_htc_2.6.25),
I'm having this error (below),  Could you please advise how to get
around the compilation.

include/asm/page.h:103:2: error: #error Unknown user operations model
In file included from include/asm/semaphore.h:13,
                 from include/linux/sched.h:64,
                 from arch/arm/kernel/asm-offsets.c:13:
include/asm/locks.h:15:5: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from include/linux/mm.h:39,
                 from arch/arm/kernel/asm-offsets.c:14:
include/asm/pgtable.h:24:25: error: asm/arch/mm.h: No such file or
directory
make[1]: *** [arch/arm/kernel/asm-offsets.s] Error 1
make: *** [prepare0] Error 2




Here is the detail steps that I've done before the compiling :

Also is it normal that on make, it asks a series of questions (below),
which for all I said no (N)?

ARM system type
  1. Agilent AAEC-2000 based (ARCH_AAEC2000) (NEW)
  2. Goldfish (ARCH_GOLDFISH) (NEW)
  3. ARM Ltd. Integrator family (ARCH_INTEGRATOR) (NEW)
  4. ARM Ltd. RealView family (ARCH_REALVIEW) (NEW)
  6. Atmel AT91 (ARCH_AT91) (NEW)
  7. Cirrus CL-PS7500FE (ARCH_CLPS7500) (NEW)
  8. Cirrus Logic CLPS711x/EP721x-based (ARCH_CLPS711X) (NEW)
  9. Co-EBSA285 (ARCH_CO285) (NEW)

* Power management
*
*
* Versatile platform type
*
Support Versatile/PB platform (ARCH_VERSATILE_PB) [Y/n/?] (NEW) n
Support Versatile/AB platform (MACH_VERSATILE_AB) [N/y/?] (NEW) n
*

Many Thanks.


--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

3. Bug in dalvik? Application will not load on package change

4. Ada yg bs bantu root magic ga?utk daerah bandung!ada master android bdg ga?

5. Ada yg bs bantu root magic ga?utk daerah bandung!ada master android bdg ga?

6. Posting lost

7. Android Lock-down