Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

java - Delete call log in android for particular number

I am trying to delete all call logs of particular number.

try {
    String strNumberOne[] = {number};
    Cursor cursor = 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));                            
            getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
        } while (cursor.moveToNext());
    }
} catch (Exception ex) {
    System.out.print("Exception here ");
}

I want to fire a LIKE query, because the mobNum saved in callLog is +916666666666 and i am passing number 6666666666. so its not matching. can anybody help me to overcome this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this code to delete any particular number from history

String number="4666";//any number
Uri CALLLOG_URI = Uri.parse("content://call_log/calls"); 
context.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.NUMBER +"=?",new String[]{number});

you can also delete call log by user name by doing this

context.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.CACHED_NAME +"=?",new String[]{name});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...