views:

36

answers:

2

Hi,

I have written code to add a number in contact book when the application is used.

    ContentResolver cr = getContentResolver();
    Uri phoneUri = null;
    ContentValues values = new ContentValues();
    values.put(People.NAME, "stack");

    Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
    phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
    values.clear();
    values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
    values.put(People.Phones.NUMBER, "9879958170");
    getContentResolver().insert(phoneUri, values);

and even added the permission in .manifest file.

<uses-permission android:name="android.permission.READ_CONTACTS"
    android:enabled="true" />
<uses-permission android:name="android.permission.WRITE_CONTACTS"
    android:enabled="true" />

this is working on emulator the contact gets added but..when i put this application into device....there is no contact with name stack...

Can anyone help me and let me know if i have done any mistake.

Thanks in advance:)

A: 

what phone do you have? Some phones (ex. samsung) have a modified contact-app installed, maybe thats the reason.

Marco Schmid
A: 

What version of android is your phone running? You're using the old contacts API here and if your phone is running Eclair or better, though these api calls should still technically work, they are not recommended. Especially when we're talking about a manufacturer customized phone app the results might be a little unpredictable.

Also, sometimes if you don't add your contact to the "My Contacts" system group, the contact will not appear in the contacts application. This is not true for every contacts app but I have seen it happen in a few cases.

Please give us a bit more info so we can answer your question properly. (Model of phone, android version its running, etc)

Marloke
Model of phone-->samsung android version --->android2.1
Jyothi Attaluri
I assume you mean the Galaxy S? Yeah I would definitely recommend switching to the new ContactsContract api instead of the old Contacts (People) api that you're using now. I haven't tested the old API on the galaxy S but I suspect its not interacting with the accounts properly.
Marloke
Another possibility is that you don't actually have a Google account setup on that phone. Make sure to check that as well. The old contacts api only interacts with the first Google account on the phone.
Marloke