Monday, July 4, 2011

[android-developers] Android device require to be re-booted in order to view newly added contact - code snippet attached

Hi all,

I am trying to insert contacts into SIM card and delete from it. But
it needs the phone to be re-started in order to update the changes.
For your reference, I am quoting the code I use for inserting a
contact.

//Before insertion - printing the contacts

Cursor c =
getApplicationContext().getContentResolver().query(
Uri.parse("content://icc/adn"), null, null, null,
null);
if (c.moveToFirst()) {
do {
name = c.getString(0);
number = c.getString(1);
Log.d(TAG, "******Before insertion -- name &
number values*******"
+ name + "---" + number);

} while (c.moveToNext());
}

//Inserting a new contact
ContentValues cv = new ContentValues();
cv.put("tag", "George");
cv.put("number", "9946957887");
Uri inserted =
getApplicationContext().getContentResolver()
.insert(Uri.parse("content://icc/adn"), cv);
getApplicationContext().getContentResolver().notifyChange(
inserted, null);


// After insertion, values printed. The newly added
contact not shown and
// this newly added contact gets added only after device
is re-booted

Cursor c1 =
getApplicationContext().getContentResolver().query(
Uri.parse("content://icc/adn"), null, null, null,
null);
if (c1.moveToFirst()) {
do {
name = c1.getString(0);
number = c1.getString(1);
Log.d(TAG, "******after insertion -- name & number
values*******"
+ name + "---" + number);

} while (c1.moveToNext());
}


Can any of the experts kindly review this and throw some light for the
reason behind, the newly added contact details (name and number) not
getting displayed immediately after insertion (while observed through
logs) and displayed correctly in logs after the device device is be re-
booted.

Any help in this regard, which would lead me to the correct solution
will be well appreciated surely.

Best Regards,
Anees

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment