android adding number to Call logs

2020-02-28 03:42发布

问题:

Is it by anyway possible to write to call logs database?? I mean i want to add selected numbers to the call history. I tried searching the tutorial on net but couldn't find any... Though 1 thing is for sure, IT CAN BE DONE. coz i have seen lots of applications online, which restore call logs, so i guess we can modify the call history database somehow(but how exactly is not clear with me).

i already read this post but it happens to be posted a long time back.

Any help will be appreciated! Thanx!

回答1:

You can use this snippet to add new records to the existing Call logs content provider:

public static void insertPlaceholderCall(ContentResolver contentResolver, String number){
    ContentValues values = new ContentValues();
    values.put(CallLog.Calls.NUMBER, number);
    values.put(CallLog.Calls.DATE, System.currentTimeMillis());
    values.put(CallLog.Calls.DURATION, 0);
    values.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE);
    values.put(CallLog.Calls.NEW, 1);
    values.put(CallLog.Calls.CACHED_NAME, "");
    values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
    values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
    Log.d(TAG, "Inserting call log placeholder for " + number);
    contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
}

(Code taken from Google Voice Callback for Android)

Remember to add the permissions in the Manifest

<uses-permission
    android:name="android.permission.READ_CONTACTS"/>
<uses-permission
    android:name="android.permission.WRITE_CONTACTS"/>


回答2:

The linked post explains it very well so I don't know why you are asking again. You cannot modify the call logs unless you keep your own database or your own firmware.