Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete call from call log after call end

I am new to Android development. I want to make a call to a number but I don't want to store the number in my Call log. How can I delete the number from call log after the call ends?

like image 948
Shivalinga Avatar asked Mar 19 '11 10:03

Shivalinga


People also ask

Can you delete a call from your call log?

Open your device's Phone app . Tap Recents . Call History. Clear call history.

How do I empty my call log?

Tap the box to delete that call, or tap the All checkbox (at the top of the list) to select all calls. Tap Delete. It's at the top-right corner of the screen. The call history is now deleted.

How can I delete recent call history after deleting?

Here's how to do: On an old Android phone: Factory reset your device > Choose to restore Google Drive backup during the setup process > Follow the on-screen instructions to finish restoring and all call logs will be restored.

Do call logs get deleted automatically?

However, you can visit Settings, then Call recording, and change the option of when to delete call recordings. Tap on Delete recordings. Then make your choice between Never, After 7 days, After 14 days, or After 30 days. I hope this answers your question!


2 Answers

First you have to set up a broadcast receiver to detect the phone state. Here's the exact same question: Stackoverflow - Intent to be fired when a call ends?

And now for deleting the call log entry, here is the first link on google: Call log deletion in Android
In the example he deletes all call entry for a specific number, but you can change the query to delete the entry for a specific call log id.

Hope this helps. Cheers

like image 195
clauziere Avatar answered Oct 12 '22 08:10

clauziere


Im using 4.2.2 anyway i had to modify the aftab's code as it was not working for me. It could be a asych issue giving what i was trying to do is update the call log right after an incoming call is ended. I think i have to give O/S enough time to update the table before i delete the entry or it wont exist :

private void deleteNumber(String phoneNumber) {

    try {
        Thread.sleep(4000);
        String strNumberOne[] = { phoneNumber };
        Cursor cursor = context.getContentResolver().query(
                CallLog.Calls.CONTENT_URI, null,
                CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
        boolean bol = cursor.moveToFirst();
        if (bol) {
            do {
                int idOfRowToDelete = cursor.getInt(cursor
                        .getColumnIndex(CallLog.Calls._ID));
                context.getContentResolver().delete(
                        CallLog.Calls.CONTENT_URI,
                        CallLog.Calls._ID + "= ? ",
                        new String[] { String.valueOf(idOfRowToDelete) });
            } while (cursor.moveToNext());
        }
    } catch (Exception ex) {
        Log.v("deleteNumber",
                "Exception, unable to remove # from call log: "
                        + ex.toString());
    }
}

and to call the function i run on another thread (since im sleeping) :

  new Thread() {
 public void run() {
deleteNumber(incomingNumber);
    }
}.start();

after adding the sleep it seems to work when trying to delete right after a call is ended.

UPDATE: after last comment realized we can set up a contentobserver on the android provider call log uri:

public class BlockerContentObserver extends ContentObserver{

private Context context;
private String phoneNumber;


public void setPhoneNumber(String phoneNumber) {
    this.phoneNumber = phoneNumber;
}

public BlockerContentObserver(Handler handler,Context context) {
    super(handler);
this.context=context;
}

 @Override
    public boolean deliverSelfNotifications() {
        return true;
    }

@Override
public void onChange(boolean selfChange) {
    // TODO Auto-generated method stub
    super.onChange(selfChange);
    Log.v(Consts.TAG,"has call log changed:"+selfChange);
    deleteNumber(phoneNumber);

}   

private void deleteNumber(String phoneNumber) {


    try {

        String strNumberOne[] = { phoneNumber };
        Cursor cursor = context.getContentResolver().query(
                CallLog.Calls.CONTENT_URI, null,
                CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
        boolean bol = cursor.moveToFirst();
        if (bol) {
            do {
                int idOfRowToDelete = cursor.getInt(cursor
                        .getColumnIndex(CallLog.Calls._ID));
                context.getContentResolver().delete(
                        CallLog.Calls.CONTENT_URI,
                        CallLog.Calls._ID + "= ? ",
                        new String[] { String.valueOf(idOfRowToDelete) });
            } while (cursor.moveToNext());
        }
    } catch (Exception ex) {
        Log.v(Consts.TAG,
                "Exception, unable to remove # from call log: "
                        + ex.toString());
    }
}

}

Now we register to listen to changes in the call log DB using this:

mContentObserver = new BlockerContentObserver(new Handler(), context);

then we make a method to either register for events or unreigster:

/*handles the registration of our content observer used for monitoring the call log*/
private void RegisterContentObserver(boolean shouldRegister){
    if(shouldRegister)
    {

        context.getContentResolver().registerContentObserver(
                android.provider.CallLog.Calls.CONTENT_URI,
                true,
                mContentObserver);

    }
else {

    try {  
        context.getContentResolver().unregisterContentObserver(mContentObserver);  
    } catch (IllegalStateException ise) {  
        // Do Nothing.  Observer has already been unregistered.  
    }  

}
    }
like image 33
j2emanue Avatar answered Oct 12 '22 06:10

j2emanue