Thursday, 6 May 2021

Android ContentResolver.NotifyChange() not working

First, I read call logs, move to first row, and get row id.

Then I update the row using content resolver using row id as query string. I do this to change last call log to some other number.

Android.Database.ICursor cursor = Application.Context.ContentResolver.Query(CallLog.Calls.ContentUri, null, null, null, CallLog.Calls.Date + " DESC limit 1;");
cursor.MoveToFirst();
string queryString = "_ID='" + cursor.GetInt(37) + "'";
ContentValues values = new ContentValues();
values.Put(CallLog.Calls.Number, ActiveCallMonitor.realcaller);
values.Put(CallLog.Calls.CachedNormalizedNumber, ActiveCallMonitor.realcaller);
values.Put(CallLog.Calls.New, 1);
Application.Context.ContentResolver.Update(CallLog.Calls.ContentUri, values, queryString, null); 

var returnUri = ContentUris.WithAppendedId(CallLog.Calls.ContentUri, id);
Application.Context.ContentResolver.NotifyChange(returnUri, null);

Now this change will show in apps that read call logs every time. But other apps like Truecaller show same old call logs because they only only listen to changes in database. Which Eventually means that NotifyChange is not working.



from Android ContentResolver.NotifyChange() not working

No comments:

Post a Comment