mContext
is not initialized..SO it giving you NullPointerException
.
change your code like this..
public void onReceive(Context context, Intent intent) {
mContext=context;
SaveCallLog();
}
add this permission..in manifest
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
Based on OP requirement..
change your code like this and try..
// here change where condition to get only those call logs those are not
// sent before
Cursor cursor = contentResolver.query(uri, null, null, null,
"date DESC");
try {
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
phNumber = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.NUMBER));
callType = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.TYPE));
callDate = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.DATE));
callDuration = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.DURATION));
dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
default:
dir = "REJECTED";
}
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}