wifi - Strange behaviour on android postioning -


i have pretty interesting case application im working on. need take current location of phone , testing application 2 testing devices. on samsung fame takes current location , updates every time activate event, on samsung galaxy s4 there no updates. gives me same coordinates. im pretty sure wrong code, cant figure out what. both of phones wifi turnded on , mobile data turned off.

this code on application:  import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.provider.settings; import android.util.log; import android.webkit.webview.findlistener; import android.widget.textview;  public final class gpstracker implements locationlistener {      private final context mcontext;     public boolean isgpsenabled = false;     boolean isnetworkenabled = false;     boolean cangetlocation = false;     location location; // location     double latitude; // latitude     double longitude; // longitude     double accuracy;      // minimum distance change updates in meters     private static final long min_distance_change_for_updates = 1; // 10 meters      // minimum time between updates in milliseconds     private static final long min_time_bw_updates = 1; // 1 minute      // declaring location manager     protected locationmanager locationmanager;      public gpstracker(context context) {         this.mcontext = context;         getlocation();     }      /**      * function user's current location      *       * @return      */     public location getlocation() {         try {             locationmanager = (locationmanager) mcontext                     .getsystemservice(context.location_service);              // getting gps status             isgpsenabled = locationmanager                     .isproviderenabled(locationmanager.gps_provider);              log.v("isgpsenabled", "=" + isgpsenabled);              // getting network status             isnetworkenabled = locationmanager                     .isproviderenabled(locationmanager.network_provider);              log.v("isnetworkenabled", "=" + isnetworkenabled);              if (isgpsenabled == false && isnetworkenabled == false) {                 // no network provider enabled             } else {                 this.cangetlocation = true;                 if (isnetworkenabled) {                     location=null;                     locationmanager.requestlocationupdates(                             locationmanager.network_provider,                             min_time_bw_updates,                             min_distance_change_for_updates, this);                     log.d("network", "network");                     if (locationmanager != null) {                         location = locationmanager                                 .getlastknownlocation(locationmanager.network_provider);                         if (location != null) {                             latitude = location.getlatitude();                             longitude = location.getlongitude();                         }                     }                 }                 // if gps enabled lat/long using gps services                 if (isgpsenabled) {                     location=null;                     if (location == null) {                         locationmanager.requestlocationupdates(                                 locationmanager.gps_provider,                                 min_time_bw_updates,                                 min_distance_change_for_updates, this);                         log.d("gps enabled", "gps enabled");                         if (locationmanager != null) {                             location = locationmanager                                     .getlastknownlocation(locationmanager.gps_provider);                             if (location != null) {                                 latitude = location.getlatitude();                                 longitude = location.getlongitude();                             }                         }                     }                 }             }          } catch (exception e) {             e.printstacktrace();         }          return location;     }      /**      * stop using gps listener calling function stop using gps in      * app      * */     public void stopusinggps() {         if (locationmanager != null) {             locationmanager.removeupdates(gpstracker.this);         }     }     public double getacc() {         if (location != null) {             accuracy = location.getaccuracy();         }          return accuracy;     }     /**      * function latitude      * */     public double getlatitude() {         if (location != null) {             latitude = location.getlatitude();         }          // return latitude         return latitude;     }      /**      * function longitude      * */     public double getlongitude() {         if (location != null) {             longitude = location.getlongitude();         }          // return longitude         return longitude;     }      /**      * function check gps/wifi enabled      *       * @return boolean      * */     public boolean cangetlocation() {         return this.cangetlocation;     }     public void showsettingsalert() {         alertdialog.builder alertdialog = new alertdialog.builder(mcontext);          // setting dialog title         alertdialog.settitle("gps settings");          // setting dialog message         alertdialog                 .setmessage("gps not enabled. want go settings menu?");          // on pressing settings button         alertdialog.setpositivebutton("settings",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int which) {                         intent intent = new intent(                                 settings.action_location_source_settings);                         mcontext.startactivity(intent);                     }                 });          // on pressing cancel button         alertdialog.setnegativebutton("cancel",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int which) {                         dialog.cancel();                     }                 });          // showing alert message         alertdialog.show();     }      @override     public void onlocationchanged(location location) {         location.getaccuracy();         location.getlatitude();         location.getlongitude();      }      @override     public void onproviderdisabled(string provider) {         log.e("disabled",provider);     }      @override     public void onproviderenabled(string provider) {         log.e("enabled",provider);     }     public void onstatuschanged(string provider, int status, bundle extras) {     }  } 


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -