1. Create an observer:
class CustomContentObserver extends ContentObserver { public CustomContentObserver(Handler handler) { super(handler); } @Override public boolean deliverSelfNotifications() { return false; } public void logCallLog() { long dialed; String columns[]=new String[] { CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.TYPE}; Cursor c; c = getContentResolver().query(Uri.parse("content://call_log/calls"), columns, null, null, "Calls._ID DESC");
2. Register observer:
Uri mediaUri = android.provider.CallLog.Calls.CONTENT_URI; Log.d("PhoneService", "The Encoded path of the media Uri is " + mediaUri.getEncodedPath()); CustomContentObserver custObser = new CustomContentObserver(handler); imageContentRsr.registerContentObserver(mediaUri, false, custObser);
EDIT: Starting with Jellybean (4.1), you need two permissions
<uses-permission android:name="android.permission.READ_CALL_LOG" />
So that this works and does not throw an exception to the permission denial
source share