我想知道从通话记录中删除的电话号码

时间:2016-08-02 06:02:39

标签: android telephony calllog

我可以在通话记录发生变化时收到通知,但我也需要号码

这是我的代码:

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
        }
    }

1 个答案:

答案 0 :(得分:2)

最后我得到了解决方案,但我不知道方式是否正确。这可以调用Log和ContactNumber Change

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
    }
    }