Android service class Not Implements with Activity -


android service class not implements activity. want private void getcalldetails() in service class gives error. when use implement method without service works service class gives error. want both.

 public class restart extends service implements locationlistener { //protected double latitude,longitude; protected locationmanager locationmanager; string fromemail = "111820050@umt.edu.pk"; string frompassword = "pakistan1919"; string toemails =""; // database later string emailbody ; string emailsubject; list<string> toemaillist; sqlitedatabase db; int counter=0; string name, password,serial,number1,number2; edittext etu, etp; string user; string passwordgui; cursor d, e,numb,numb2,ec; textview t1,t2; string getsimserialnumber ; string getsimoperator; string imeinumber; telephonymanager telemamanger; stringbuffer sb = new stringbuffer(); protected double latitude,longitude; @override public ibinder onbind(intent intent) {     return null; }  @override public void oncreate() {     db = openorcreatedatabase("abb", mode_private, null);   //  wifimanager wifimanager = (wifimanager) getbasecontext().getsystemservice(context.wifi_service);    // wifimanager.setwifienabled(true);     systemclock.sleep(20000);      locationmanager = (locationmanager) getsystemservice(context.location_service);     locationmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, this);      telemamanger = (telephonymanager) getsystemservice(context.telephony_service);     getsimserialnumber = telemamanger.getsimserialnumber();     imeinumber = telemamanger.getdeviceid();     getsimoperator = telemamanger.getnetworkoperatorname();      //getcalldetails();    // t1 = (textview) findviewbyid(r.id.txt_1);    // t2 = (textview) findviewbyid(r.id.txt_2);       d = db.rawquery("select serial ta3", null);      d.movetofirst();      serial = d.getstring(d.getcolumnindex("serial"));      //for ime database      d = db.rawquery("select serial ta3", null);      d.movetofirst();      serial = d.getstring(d.getcolumnindex("serial"));      //      email     ec = db.rawquery("select emailaddress ta3", null);      ec.movetofirst();      toemails = ec.getstring(ec.getcolumnindex("emailaddress"));      //for contact number database      numb = db.rawquery("select number ta3", null);      numb.movetofirst();      number1 = numb.getstring(numb.getcolumnindex("number"));       /// number2      numb2 = db.rawquery("select number2 ta3", null);      numb2.movetofirst();      number2 = numb2.getstring(numb2.getcolumnindex("number2"));      //t1.settext("db " + serial.tostring());     //t2.settext(getsimserialnumber.tostring());      if(isvalid())     {          toast.maketext(getapplicationcontext(),                 "you information successfully.", toast.length_short)                 .show();           string phoneno = number1.tostring();         string phoneno2 = number2.tostring();         string msg = " company name: " + getsimoperator + "\n" + "    sim      serial number: " + getsimserialnumber + "  ime number: " + imeinumber;         try {             smsmanager smsmanager = smsmanager.getdefault();             smsmanager.sendtextmessage(phoneno, null, msg, null, null);             smsmanager.sendtextmessage(phoneno2, null, msg, null, null);             toast.maketext(getapplicationcontext(), "message sent",                     toast.length_long).show();         } catch (exception ex) {             toast.maketext(getapplicationcontext(),                     ex.getmessage().tostring(),                     toast.length_long).show();             ex.printstacktrace();         }       }      //onstart(new intent(restart.this, callhistory.class),0); }  @override public void onproviderdisabled(string provider) {     log.d("latitude","disable"); }  @override public void onproviderenabled(string provider) {     log.d("latitude","enable"); }  @override public void onlocationchanged(location location) {      //txtlat = (textview) findviewbyid(r.id.txtlat);    // txtlat.settext("latitude:" + location.getlatitude() + "\nlongitude:" + location.getlongitude()+"\nserial number: "+"\n"+serialnumber);      toast.maketext(             getapplicationcontext(),             "latitude:" + location.getlatitude() + "\nlongitude:" + location.getlongitude(),             toast.length_long).show();      toemaillist = arrays.aslist(toemails             .split("\\s*,\\s*"));     log.i("sendmailactivity", "to list: " + toemaillist);     emailbody ="  ime number: " + imeinumber + "\n" + "   sim number: " + getsimserialnumber+ " company name: " + getsimoperator +""+  "latitude:" + location.getlatitude() + "\nlongitude:" + location.getlongitude();     emailsubject = "mobile restrt";      new sendmailtask(restart.this).execute(fromemail, frompassword, toemaillist, emailsubject, emailbody);      systemclock.sleep(10000);  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     log.d("latitude","status"); }  @override public void onstart(intent intent, int startid) {   //        intent nextscreen = new intent(restart.this, taskperform.class);   //        startactivity(nextscreen);    /*        class formail extends activity{          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              intent nextscreen = new intent(restart.this, callhistory.class);             startactivity(nextscreen);         }     }*/    // startactivity(intent);     toast.maketext(this, "my service started", toast.length_long).show();  }  @override public void ondestroy() {  }  private boolean isvalid() {     if(serial.tostring().equals(getsimserialnumber.tostring()) )         return false;     else         return true; }  /*public class callhistory extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          getcalldetails();       }     private void getcalldetails() {          string strorder = android.provider.calllog.calls.date + " desc";    *//* query calllog content provider *//*         cursor managedcursor = managedquery(calllog.calls.content_uri, null,                 null, null, strorder);         int number = managedcursor.getcolumnindex(calllog.calls.number);         int type = managedcursor.getcolumnindex(calllog.calls.type);         int date = managedcursor.getcolumnindex(calllog.calls.date);         int duration = managedcursor.getcolumnindex(calllog.calls.duration);         sb.append("call log :");           while (managedcursor.movetonext()) {             if (counter == 6)                 break;             ;             string phnum = managedcursor.getstring(number);             string calltypecode = managedcursor.getstring(type);             string strcalldate = managedcursor.getstring(date);             date calldate = new date(long.valueof(strcalldate));             string callduration = managedcursor.getstring(duration);             string calltype = null;             int callcode = integer.parseint(calltypecode);             switch (callcode) {                 case calllog.calls.outgoing_type:                     calltype = "outgoing";                     break;                 case calllog.calls.incoming_type:                     calltype = "incoming";                     break;                 case calllog.calls.missed_type:                     calltype = "missed";                     break;             }             sb.append("\nphone number:--- " + phnum + " \ncall type:--- "                     + calltype + " \ncall date:--- " + calldate                     + " \ncall duration in sec :--- " + callduration);             sb.append("\n----------------------------------");             counter++;         }         managedcursor.close();      }    }*/   } 

in order connect service activity have bind activty ,and 2 major things have consider is

  1. it should started activity.
  2. it died once activity destroyed.

http:refer link


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -