如何从android中的通话记录中删除拨号号码?

时间:2014-02-12 06:49:50

标签: android android-broadcast

如果有人有想法从android中的通话记录中删除拨号号码。当我们拨打哪个方法将在广播接收器中呼叫时。请提前帮助我。

public class IncommingCallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context mContext, Intent intent) {
        // Get the current Phone State
        this.mContext = mContext;
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        callerPhoneNumber = intent.getExtras().getString("incoming_number");
        if (state == null)
            return;
        // If phone state "Rininging"
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            ring = true;
            flag=0;
            // Get the Caller's Phone Number
        }
        // If incoming call is received
        if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            callReceived = true;
            flag=1;
        }
        // If phone is Idle
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            // If phone was ringing(ring=true) and not
            // received(callReceived=false) , then it is a missed call
            if (ring == true && callReceived == false ) {
                flag=2;
            }
        }

2 个答案:

答案 0 :(得分:1)

尝试按呼叫ID删除呼叫记录。使用下面的代码

int res = Call_logs.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);
if (res == 1) 
{
      Uri uri = Uri.parse("content://call_log/calls");
      int d  = getContentResolver().delete(uri, null, null);        
}

答案 1 :(得分:1)

尝试使用此功能:

public void deleteAnEntryFromCallLog(String number) 
{ 
try 
{ 
    Uri CALLLOG_URI = Uri.parse("content://call_log/calls"); 
    getApplicationContext().getContentResolver().delete(CALLLOG_URI,CallLog.Calls.NUMBER +"=?",new String[]{number}); 
} 
catch(Exception e) 
{ 
    e.printStackTrace(); 
} 
}