如何在Android中以降序获取呼叫日志列表我的代码在这里,但它不起作用。它只是显示通话记录的升序。
我的代码是
@Override
protected List<CallLogDetail> doInBackground(Void... params) {
data = new ArrayList<CallLogDetail>();
managedCursor1=getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
null, null, null);
int number = managedCursor1.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor1.getColumnIndex(CallLog.Calls.TYPE);
int Name= managedCursor1.getColumnIndex(CallLog.Calls.CACHED_NAME);
while (managedCursor1.moveToNext()) {
String phNumber = managedCursor1.getString(number);
String Names = managedCursor1.getString(Name);
Bitmap photo = null
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI,
Uri.encode(phNumber));
String[] projection = new String[]{ContactsContract.Contacts._ID};
Cursor c = getActivity().getContentResolver().query(contactUri, projection,
null, null, null);
if (c.moveToFirst()) {
contactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
inputStream = ContactsContract.Contacts.openContactPhotoInputStream(getActivity().getContentResolver(),
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(contactID)));
}
c.close();
if (inputStream != null) {
photo = BitmapFactory.decodeStream(inputStream);
}
String callTypeCode = managedCursor1.getString(type);
int callcode = Integer.parseInt(callTypeCode);
String callType = null;
switch (callcode) {
case CallLog.Calls.OUTGOING_TYPE:
callType = "Outgoing";
break;
case CallLog.Calls.INCOMING_TYPE:
callType = "Incoming";
break;
case CallLog.Calls.MISSED_TYPE:
callType = "Missed";
break;
}
CallLogDetail c = new CallLogDetail(Names, phNumber, photo, callType);
data.add(c);
Comparator<CallLogDetail> callLogDetailComparator = Collections.reverseOrder();
Collections.sort(data, callLogDetailComparator); }
Run Code Online (Sandbox Code Playgroud)
我正在使用Comparator和Collections.reverseOrder(),但无法正常工作。
“ COLUMN_FOR_SORT DESC”不适用于我。
我用了:
Cursor managedCursor1 = getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, null, null,CallLog.Calls.DATE + " DESC");
Run Code Online (Sandbox Code Playgroud)
做到了。
| 归档时间: |
|
| 查看次数: |
1879 次 |
| 最近记录: |