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.
开发者_StackOverflow中文版<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:)
what phone do you have? Some phones (ex. samsung) have a modified contact-app installed, maybe thats the reason.
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)
精彩评论