get All Call Log About A Caller - Android Phone

Android examples for Phone:Phone Call

Description

get All Call Log About A Caller

Demo Code


//package com.java2s;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
import android.util.Log;

public class Main {
    private static final String TAG = "CallLogUtils";

    public static Cursor getAllCallLogAboutACaller(Context context,
            String callerNumber) {
        // cancello la chiamata in uscita se nelle preferenze ? settata tale opzione
        Uri delUri = Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, "");
        Cursor cursor = context.getContentResolver().query(delUri, null,
                android.provider.CallLog.Calls.NUMBER + "=?",
                new String[] { "404" }, null);
        try {//from ww  w  . ja  v a2  s .c om
            boolean moveToFirst = cursor.moveToFirst();
            Log.i("MOVETOFIRST", "moveToFirst=" + moveToFirst);
            do {
                int numberColumn = cursor
                        .getColumnIndex(android.provider.CallLog.Calls.NUMBER);
                String callerPhoneNumber = cursor.getString(numberColumn);
                Log.i(TAG, "numero : " + callerPhoneNumber);
            } while (cursor.moveToNext());

        } catch (Exception e) {
            Log.e(TAG, "Problem moving to first entry", e);
        }
        return cursor;
    }
}

Related Tutorials