Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid GPS. Location Listener does not want to acquire a fix :(
    text
    copied!<p>Here is a code below that suppose to listen for GPS updates and send notifications to main activity</p> <p>However it does not seem to be working :)</p> <p>No errors, only onLocationChanged is not called!</p> <p>Funny thing is: when I run some other app to get GPS fix and after that start my app => onLocationChanged gets called, only accuracy is degrading, and eventually fix is lost.</p> <p>I also tried to add to this code GPS listener=> it works, satellites in view got reported every second, only fix is never accuired.</p> <p>What the hell is going on? :)</p> <p>public class PhoneGPSpos{</p> <pre><code>private Handler myHandler = null; private LocationManager lm; private LocationListener locationListener; private Location currentBest; Context m_context; </code></pre> <p>public PhoneGPSpos(Context context, Handler handler) {</p> <pre><code> myHandler = handler; m_context = context; lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // Bundle bundle = new Bundle(); // boolean xtraInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_xtra_injection",bundle); // boolean timeInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_time_injection",bundle); currentBest = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); locationListener = new LocationListener() { public void onLocationChanged(Location location) { Log.w("Compass", "Loc"); if (location != null) { currentBest = location; Message msg = new Message(); msg.arg1 = 5; myHandler.sendMessage(msg); } } public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Compass", "Stat"); } public void onProviderEnabled(String provider) { Log.d("Compass", "Prov e"); } public void onProviderDisabled(String provider) { Log.d("Compass", "Prov d"); } }; } public void requestGPS() { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); Log.d("Compass", "gps requested"); } public void stopGPS() { Log.d("Compass", "gps stopped"); lm.removeUpdates(locationListener); } public synchronized Location getBest() { return currentBest; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload