2016-08-02 53 views
2

只要通話記錄發生變化,我就能得到通知,但我也需要號碼我想知道通話的電話號碼,從通話記錄中刪除

這裏是我的代碼:

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

回答

2

最後我得到了解決此,但,但我不知道是否方式正確與否。這個工程通話記錄和ContactNumber變化

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