开发者

How to add phone logs programmatically in Android?

I want to add phone logs programmatically from my custom application. Using the following code for adding phone开发者_运维百科 logs, I get a new phone log in phone log list, but it only adds the phone number in the list, not "call type", "duration", and "Date".

What did I miss?

    ContentValues values = null;
    for (int i = 0; i < length; i++) {
        Info info = (Info) Variables.elementAt(i);
        int index = info.getIndex();
        String value = info.getValue();
        values = new ContentValues();
        if (value != null) {
            if (index == Constants.NUMBER_TYPE) {
                values.put(CallLog.Calls.CACHED_NUMBER_TYPE, value);
            } else if (index == Constants.CALL_TYPE) {
                values.put(CallLog.Calls.TYPE, value);
            } else if (index == Constants.DATE) {
                values.put(CallLog.Calls.DATE, value);
            } else if (index == Constants.DURATION) {
                values.put(CallLog.Calls.DURATION, value);
            }
        }
    }
    values.put(CallLog.Calls.NUMBER, phoneNumber);
    activity.getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);


I tried this in my LG P350. Its surely works with the android.permission.WRITE_CONTACTS permission.

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, "1234567890");
getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜