android - how to get the number of the most frequent value entry in callLog.calls? -
call log calls entry - name number type date called - jed 12345 incoming 7-18-2013 - roger 14611 incoming 7-18-2013 - jed 12345 incoming 7-18-2013 - jed 12345 incoming 7-18-2013 - kevin 11111 incoming 7-18-2013
hi, want query in android such retrieve jed, 12345 << since has repetitive value in list, im suppose in sqlite (android query) dont know functions invoke code used, able recent number called instead of 1 entries. how do query?
date date=new date() ; cursor c = contxt.getcontentresolver().query(calllog.calls.content_uri, null, calllog.calls.type + " , " + calllog.calls.incoming_type + " , " + calllog.calls.date + ">=" + date.getdate() , null, calllog.calls.date + " desc limit 1"); if(c!=null) do{ int callcounter = c.getcount(); string num = calllog_cursor.getstring(calllog_cursor .getcolumnindex(android.provider.calllog.calls.number)); }while(c.movetofirst());
if you're looking single query job, i'm sorry (as far sa google skills goes) doesn't exist. i've solved in way might find useful.
create function somewhere in activity:
public static void searchanddisplay(arraylist<string> arr) { arraylist<string> list1 = new arraylist(); arraylist<integer> list2 = new arraylist(); (int = 0; < 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); } } (int = 0; < list1.size(); i++) { system.out.println("number " + list1.get(i) + " occurs " + list2.get(i) + " times."); } int maxcount = 0; int index = -1; (int = 0; < 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 might want something/return number highest occurences. }
then want cursor use this:
date date = new date(); arraylist<string> allnumbers = new arraylist(); cursor c = this.getcontentresolver().query( calllog.calls.content_uri, null, calllog.calls.type + " , " + calllog.calls.incoming_type + " , " + calllog.calls.date + ">=" + date.getdate(), null, calllog.calls.number); allnumbers.clear(); if (c != null) c.movetofirst(); (int = 0; c.getcount() > i; i++) { string number1 = c.getstring(0); allnumbers.add(number1); c.movetonext(); } searchanddisplay(allnumbers);
you might want double-check numbers receive correct.
let me know how goes. :)
Comments
Post a Comment