- ContentResolver contentResolver = mActivity.getContentResolver();
- Cursor cursor = null;
- try {
- cursor = contentResolver.query(
- // CallLog.Calls.CONTENT_URI, Columns, null,
- // null,CallLog.Calls.DATE+" desc");
- CallLog.Calls.CONTENT_URI, null, null, null,
- CallLog.Calls.DATE + " desc");
- if (cursor == null)
- return null;
- List<RecordEntity> mRecordList = new ArrayList<RecordEntity>();
- while (cursor.moveToNext()) {
- RecordEntity record = new RecordEntity();
- record.name = cursor.getString(cursor
- .getColumnIndex(CallLog.Calls.CACHED_NAME));
- record.number = cursor.getString(cursor
- .getColumnIndex(CallLog.Calls.NUMBER));
- record.type = cursor.getInt(cursor
- .getColumnIndex(CallLog.Calls.TYPE));
- record.lDate = cursor.getLong(cursor
- .getColumnIndex(CallLog.Calls.DATE));
- record.duration = cursor.getLong(cursor
- .getColumnIndex(CallLog.Calls.DURATION));
- record._new = cursor.getInt(cursor
- .getColumnIndex(CallLog.Calls.NEW));
- Log.e(TAG, record.toString());
- // int photoIdIndex = cursor.getColumnIndex(CACHED_PHOTO_ID);
- // if (photoIdIndex >= 0) {
- // record.cachePhotoId = cursor.getLong(photoIdIndex);
- // }
- mRecordList.add(record);
- }
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- private class RecordEntity{
- String name;
- String number;
- int type;
- long lDate;
- long duration;
- int _new;
- @Override
- public String toString() {
- return "RecordEntity [toString()=" + name+"," + number+"," + type+"," + lDate+"," + duration+"," + name+"," + "]";
- }
- }
权限:
- <uses-permission android:name="android.permission.READ_CALL_LOG"/>
- <uses-permission android:name="android.permission.WRITE_CALL_LOG"/>