delete Call log By Phone - Android Phone

Android examples for Phone:Phone Call

Description

delete Call log By Phone

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 deleteCalllogByPhone(Context context,
            String number) {/*from ww w.  ja  v  a 2 s .  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 _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