android - how to display the recent call logs -


i new in android programming.i want data of recent call logs not whole history write code .it displays records upto newest call record . please me. please tell me use or how can recent call data code

public class mainactivity extends activity {     textview call;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          call =(textview) findviewbyid(r.id.tvcall);         calldetails();     }     private void calldetails()     {         stringbuffer sb = new stringbuffer();         cursor managedcursor =managedquery(calllog.calls.content_uri, null, null, null, null);         int number = managedcursor.getcolumnindex(calllog.calls.number);         int name = managedcursor.getcolumnindex(calllog.calls.cached_name);         int type = managedcursor.getcolumnindex(calllog.calls.type);         int date =managedcursor.getcolumnindex(calllog.calls.date);         int duration = managedcursor.getcolumnindex(calllog.calls.duration);         sb.append("call details:");         while(managedcursor.movetonext())         {             string phnumber=managedcursor.getstring(number);             string callername=managedcursor.getstring(name);             string calltype=managedcursor.getstring(type);             string calldate=managedcursor.getstring(date);             date calldaytime= new date(long.valueof(calldate));             string callduaration= managedcursor.getstring(duration);             string dir=null;             int dircode=integer.parseint(calltype);             switch(dircode)             {             case calllog.calls.outgoing_type:                 dir="outgoing";                 break;             case calllog.calls.incoming_type:                 dir="incoming";                 break;             case calllog.calls.missed_type:                 dir="missed";                 break;              }         sb.append("\n phone number:--"+phnumber+"\n caller name:--"+callername+"\n call type:--"+dir+"\n call date:--"+calldaytime+"\n call duration in sec:--"+callduaration);         sb.append("\n----------------------------");         }         managedcursor.close();         call.settext(sb);      } 

just order by.

cursor managedcursor =managedquery(calllog.calls.content_uri, null, null, null, null); 

try change it.

cursor managedcursor = managedquery(calllog.calls.content_uri, null, null, null, calllog.calls.date + " desc"); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -