android - Fragment Getting Method from Another Class -
i have android app uses fragments. i'm following tutorial (calllogs tutorial) calls history.
i have class made tutorial in link want data class , use in 1 of fragments.
i've tried following;
int callsmade = new getusage().getcalldetails(); string callsmade = string.valueof(callsmade); log.e("calls made:", "texts: " + callsmade);
but keep getting error on "cursor managedcursor" line (nb: i've changed managedcursor getcontentresolver since managedcursor deprecated , error too)
is there i'm doing wrong here? anthing ye can think of can change?
thanks alot can provide.
edit: code getcalldetails();
public int getcalldetails() { stringbuffer sb = new stringbuffer(); cursor callscursor = getcontentresolver().query( calllog.calls.content_uri,null, null,null, calllog.calls.date + " desc"); //cursor plancursor=planshelper.query("plans", null, null, null, null); int name = callscursor.getcolumnindex( calllog.calls.cached_name ); int number = callscursor.getcolumnindex( calllog.calls.number ); int type = callscursor.getcolumnindex( calllog.calls.type ); int date = callscursor.getcolumnindex( calllog.calls.date); int duration = callscursor.getcolumnindex( calllog.calls.duration); int allduration = 0; sb.append( "call details :"); while ( callscursor.movetonext() ) { string phname = callscursor.getstring( name ); string phnumber = callscursor.getstring( number ); string calltype = callscursor.getstring( type ); int calltypecode = integer.parseint(calltype); string calldate = callscursor.getstring( date ); date formatdate = new date(long.valueof(calldate)); simpledateformat sdf = new simpledateformat("dd/mm/yyyy"); string datestr = sdf.format(formatdate); string userdate = "18/03/2014"; //date parseddate = sdf.parse(userdate1); calendar c = calendar.getinstance(); try { c.settime(sdf.parse(userdate)); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } c.add(calendar.date, -5); // number of days add userdate = sdf.format(c.gettime()); // dt new date string callduration = callscursor.getstring(duration); float durationtofloat =float.parsefloat(callduration); float durationtomins = durationtofloat/60; int durationrounded = math.round(durationtomins); int calldurationmin = durationrounded; if(calltypecode==calllog.calls.outgoing_type) { //if(datestr.equals(userdate) || datestr.equals(userdate1)) if(formatdate.after(c.gettime())) { sb.append("\nname:--- " + phname + "\nphone number:--- " + phnumber + " \ncall date:--- " + datestr + " \ncall duration in min :--- " + calldurationmin); sb.append("\n----------------------------------"); allduration = allduration + calldurationmin; log.d(getclass().getsimplename(), "done"); } } } sb.append("##" + allduration + "##"); getcalls.settext(sb.tostring()); callscursor.close(); return allduration; }
change line int callsmade = new getusage().getcalldetails(); following code
activity activity = getactivity(); if(activity instanceof getusage) { getusage myactivity = (getusage) activity; myactivity.getcalldetails(); }
Comments
Post a Comment