Reputation: 1520
I want to retrieve list of missed call from call log db in android. But if there is more than one missed call from a number than i want only one record for that number with a column name indicating number of missed call from that particular number. I would also like to fetch other details such as name,phone type extra. I have written code which gives all missed call list . For ex if i have two missed call from same number than i get two record.
Below is my code
String strSelection=null;
String projection[]={Calls.CACHED_NAME,
Calls.NUMBER,
Calls.CACHED_NUMBER_TYPE,
Calls.CACHED_NUMBER_LABEL};
strSelection = android.provider.CallLog.Calls.TYPE + " = "
+ android.provider.CallLog.Calls.MISSED_TYPE;
Cursor missedCursor = null;
missedCursor = mContext.getContentResolver()
.query(Calls.CONTENT_URI, projection,strSelection, null,
Calls.DATE + " DESC");
Please help in improving my code.
Thanks.
Upvotes: 1
Views: 1601
Reputation: 688
I've created selection
CallLog.Calls._ID + " in (SELECT " + CallLog.Calls._ID + " FROM calls WHERE type != " + CallLog.Calls.VOICEMAIL_TYPE + " GROUP BY " + CallLog.Calls.NUMBER+")"
and it works for me, but NOTE we used hardcoded table name "calls"
Upvotes: 2
Reputation: 8028
You need to add the Group By param
strSelection = android.provider.CallLog.Calls.TYPE + " = " +
android.provider.CallLog.Calls.MISSED_TYPE +") GROUP BY (" + Calls.NUMBER+ ")";
Upvotes: 0