我想将Android Call Log中第一个条目的CallLog.Calls.TYPE
字段从MISSED
更新为INCOMING
。我已经读过书了,开发人员参考并谷歌了这篇文章,我相当确定我的代码是正确的。但是,当我实际调用update()
时,结果是没有更新任何记录。我的代码示例如下。
在你问之前:
WRITE_CONTACTS
有人能帮个忙吗?
ContentValues newValues = new ContentValues();
newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
newValues.put(CallLog.Calls.DURATION, 50);
int result = OsmoService.context.getContentResolver().update(
ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0),
newValues,null,null);
发布于 2011-04-27 02:22:56
如果您更新上面的代码并替换行:
ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0)
使用这一行:
Uri.parse("content://call_log/calls")
它起作用了。我不知道为什么,但是内容URI有些地方不正确。
示例:
ContentValues newValues = new ContentValues();
newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
newValues.put(CallLog.Calls.DURATION, 50);
int result = OsmoService.context.getContentResolver().update(
Uri.parse("content://call_log/calls"),
newValues,
null,
null);
发布于 2015-10-26 01:49:03
ContentValues cv = new ContentValues();
cv.put(CallLog.Calls.NUMBER,"7070770"); // contact number
cv.put(CallLog.Calls.TYPE,1); // type
cv.put(CallLog.Calls.DURATION, 120); // duration in second
getContentResolver().insert(CallLog.CONTENT_URI, cv);
发布于 2018-03-21 17:37:16
例如CallLog.Calls.CACHED_NAME
private void updateCachedName(int id, @NonNull String name) {
ContentValues contentValues = new ContentValues();
contentValues.put(CallLog.Calls.CACHED_NAME, name);
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {
getContext().getContentResolver().update(CallLog.Calls.CONTENT_URI, contentValues, CallLog.Calls._ID + "=" + id, null);
}
}
https://stackoverflow.com/questions/5635874
复制相似问题