gps - Is LocationListener in android works like loop? -


i used locationlistener calculate speed of moving mobile. used location.getspeed() speed. task if device speed crosses exceeds set speed limit send sms alert- on speed other mobile number. used flag variable boolean flag; check conditions. problem if mobile travel above limited speed 10 seconds continuously has send 1 message. app sends message long device goes above speed. set flag variable no use. code is

 private void sendoverspeedalert() {     toast.maketext(mainpage.this,"over speed alert set",toast.length_long).show();     final sharedpreferences account=getsharedpreferences("admins",mode_private);      string overspeed=account.getstring("osa", "");     double overspeedkm=double.parsedouble(overspeed);     final decimalformat dformat = new decimalformat("#");     string overspeedformat=dformat.format(overspeedkm);     final double overspeeddouble=double.parsedouble(overspeedformat);      final locationmanager locationmanager=(locationmanager)getsystemservice(context.location_service);     locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, new locationlistener() {         @override         public void onlocationchanged(final location location) {             final double currentspeed=(location.getspeed())*3.6;             string currentspeedstring =dformat.format(currentspeed);             final double currentspeeddouble=double.parsedouble(currentspeedstring);              if ((currentspeeddouble>=overspeeddouble)&&(flag==false)){                  countdowntimer countdowntimer=new countdowntimer(10000,1000) {                     @override                     public void ontick(long millisuntilfinished) {                      }                      @override                     public void onfinish() {                         double latitude=location.getlatitude();                         double longitude=location.getlongitude();                         decimalformat decimalformat=new decimalformat("#.####");                         date date=new date();                         simpledateformat sdf=new simpledateformat("kk:mm");                         string time=sdf.format(date);                          smsmanager smsmanager=smsmanager.getdefault();                         string sms="'alert- on speed'\n\n'!+"+decimalformat.format(latitude)+",+"+decimalformat.format(longitude)+","+time+"'\n\nspeed= '"+currentspeeddouble+"'km/hr('"+overspeeddouble+"')";                         smsmanager.sendtextmessage(logpreferences.getstring("admin1", ""), null, sms, null, null);                         flag=true;                     }                 }.start();             }               if (currentspeeddouble<20){                  flag=false;              }         }          @override         public void onstatuschanged(string provider, int status, bundle extras) {          }          @override         public void onproviderenabled(string provider) {          }          @override         public void onproviderdisabled(string provider) {          }     }); 

http://developer.android.com/reference/android/location/locationlistener.html

it called anytime device changes location. set falg, change value when send message, 10 sec after cross limit of speed. should change right after detecting it.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -