android adding number to Call logs

匆匆过客 提交于 2019-12-18 15:02:17

问题


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.



来源:https://stackoverflow.com/questions/3166039/android-adding-number-to-call-logs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!