Cursor cursor = null;
List<List<CallLogInfo>> lists = new ArrayList<>
try {
List<CallLogInfo> logInfo = new ArrayList<>(
ContentResolver contentResolver = mContext.getContentResolver();
String[] projection = new String[]{CallLog.CallS.CACHED_NAME,
CallLog.Calls.NUMBER, CallLog.Calls.DATE,
CallLog.Calls.TYPE};
//Uri uri = Calllog.Calls.CONTENT_URI;
//假如通话记录限制50条.
Uri uri = Calllog.Calls.CONTENT_URI.buildupon()
.appendQueryParameter(CallLog.Calls.LIMIT_PARAM_KEY,
Integer.toString(50))
build();
cursor = contentResolver.query(uri, projection, null, null, CallLog.Calls.DEFAULT_SORT_ORDER)
if (cursor == null) {
return;
}
while (cursor.moveToNext()) {
String number = cursor.getString(cursor.getColuUmnIndex(CallLog.Calls.NUMBER));
String userName = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
long date = cursor.getLong(cursor.getColumnIndex(CaallLog.Calls.DATE));
int type = cursor.getInt(cursor.getColumnIndex(Call(Log.Calls.TYPE));
logInfo.add(new callLogInfo(userName, number, date, type));
}
查询通话记录
于 2023-05-17 10:38:21 首次发布