I'm working on a headset button controller and I want to add a fake/invalid call to call log to prevent phone from dialing last call when I press headset button twice (double click) in htc android phones. I tried this:
ContentValues cv = new ContentValues();
cv.put(CallLog.Calls.NUMBER, number);
cv.put(CallLog.Calls.DATE, System.currentTimeMillis());
cv.put(CallLog.Calls.DURATION, 0);
cv.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE);
cv.put(CallLog.Calls.NEW, 0);
cv.put(CallLog.Calls.CACHED_NAME, "");
cv.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
cv.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
this.getContentResolver().insert(CallLog.Calls.CONTENT_URI, cv);
And the program crashes (App has stopped error). I've set the permission in manifest file:
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
where is the problem?
/**
* insert new call log
*/
public static void insertNumber(Activity activity) {
ContentValues values = new ContentValues();
values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
values.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
values.put(CallLog.Calls.DATE, System.currentTimeMillis());
values.put(CallLog.Calls.DURATION, 50);
values.put(CallLog.Calls.NUMBER, "1234567");
activity.getContentResolver().insert(CallLog.Calls.CONTENT_URI,
values);
}
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />