Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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) {
        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();
        }
    }
}