2

I am able to get notified whenever there is a change in call log, but i need the number as well.

Here is my code:

public class MainActivity extends AppCompatActivity {    
    CallLogChangeObserverClass callLogChangeObserverClass = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        callLogChangeObserverClass = new CallLogChangeObserverClass(new Handler(), this);

        //Registering content observer
        getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI, true,
                callLogChangeObserverClass);

    }


    public class CallLogChangeObserverClass extends ContentObserver {
        public CallLogChangeObserverClass(Handler handler, Context ct) {
            super(handler);
            // TODO Auto-generated constructor stub
        }

        public void onChange(boolean selfChange) {
            Toast.makeText(getApplicationContext(), "Call Log Changed", Toast.LENGTH_LONG).show();
            //Read call Logs here
        }
    }
user1643723
  • 4,109
  • 1
  • 24
  • 48
Ramesh Kanuganti
  • 275
  • 1
  • 11

1 Answers1

2

Finally i got the solution for this but but i dont know whether the way is correct or not. this works call Log and ContactNumber Change

in onChange

execute a Query with contentResolver(), and put the data in a List
then something is deleted again 
execute a Query with contentResolver(),and assign it to tempList.
now compare the List and tempList



@Override
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);    
 final int List = totalContacts();

if (tempList < List) {
something is deleted
then remove the tempList from List you will get the deleted number

}else if (tempList == List) {
something is updated
then remove the tempList from List you will get the deleted number
}else {
       something is added(reverse the Lists)
then remove the List from tempList you will get the deleted number
    }
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ramesh Kanuganti
  • 275
  • 1
  • 11