Android 获取通话记录

				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 mRecordList = new ArrayList();
					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+"," + "]";
		}
	}


 

 

 

权限:

 

    
    


你可能感兴趣的:(Android,通话记录,联系人)