If you're looking for a single query to do the job, I'm sorry to say that it (as far sa my google skills goes) doesn't exist. I've solved it in another way that you might find useful.
Create this function somewhere in your activity:
public static void searchAndDisplay(ArrayList<String> arr) {
ArrayList<String> list1 = new ArrayList();
ArrayList<Integer> list2 = new ArrayList();
for (int i = 0; i < arr.size(); i++) {
int index = list1.indexOf(arr.get(i));
if (index != -1) {
int newCount = list2.get(index) + 1;
list2.set(index, newCount);
} else {
list1.add(arr.get(i));
list2.add(1);
}
}
for (int i = 0; i < list1.size(); i++) {
System.out.println("Number " + list1.get(i) + " occurs "
+ list2.get(i) + " times.");
}
int maxCount = 0;
int index = -1;
for (int i = 0; i < list2.size(); i++) {
if (maxCount < list2.get(i)) {
maxCount = list2.get(i);
index = i;
}
}
System.out.println("Number " + arr.get(index)
+ " has highest occurrence i.e " + maxCount); // here you might want to do something/return the number with the highest occurences.
}
Then where you want the cursor you use this:
Date date = new Date();
ArrayList<String> allnumbers = new ArrayList();
Cursor c = this.getContentResolver().query(
CallLog.Calls.CONTENT_URI,
null,
CallLog.Calls.TYPE + " AND " + CallLog.Calls.INCOMING_TYPE
+ " AND " + CallLog.Calls.DATE + ">=" + date.getDate(),
null, CallLog.Calls.NUMBER);
allnumbers.clear();
if (c != null)
c.moveToFirst();
for (int i = 0; c.getCount() > i; i++) {
String number1 = c.getString(0);
allnumbers.add(number1);
c.moveToNext();
}
searchAndDisplay(allnumbers);
You might want to double-check that the numbers you receive is correct.
Let me know how it goes. :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…