delete Recent Call Log - Android Phone

Android examples for Phone:Phone Call

Description

delete Recent Call Log

Demo Code


//package com.java2s;
import android.content.Context;
import android.database.Cursor;
import android.provider.CallLog.Calls;
import android.text.TextUtils;

public class Main {
    public static synchronized void deleteRecentLog(Context context,
            String number) {/*from   w w w .  java 2s  . co m*/
        if (TextUtils.isEmpty(number))
            return;
        try {
            Cursor cursor = context.getContentResolver().query(
                    Calls.CONTENT_URI, null, Calls.NUMBER + "=?",
                    new String[] { number }, Calls.DATE + " desc");
            if (cursor != null) {
                if (cursor.moveToNext()) {
                    long time = cursor.getLong(cursor
                            .getColumnIndex(Calls.DATE));
                    if (System.currentTimeMillis() - time < 10 * 1000) {
                        long _id = cursor.getLong(cursor
                                .getColumnIndex(Calls._ID));
                        context.getContentResolver().delete(
                                Calls.CONTENT_URI, Calls._ID + "=?",
                                new String[] { String.valueOf(_id) });
                    }
                }
                cursor.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials