0

I'm developping a simple application to monitor GPS speed. This morning i installed a couple of GPS position mockers to test my application and no one seemed to work well. Uninstalled all of them and (i don't know if this is related at any point) now when i debug my application on my N4 using ADB, the GPS won't turn on when i call .requestLocationUpdates. The gps icon doesn't show in the notification bar and no data is retrieved, onLicationChanged is never called and the function .isProvider enabled returns false..

I completly reconstructed my application to the simplest form possible. I call code copied from android.developper documentation directly on the onCreate override.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speed_monitoring);
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {

        location.getLatitude();
        Toast.makeText(getApplicationContext(), "Current speed:" + location.getSpeed(), Toast.LENGTH_SHORT).show();
    }
    public void onStatusChanged(String provider, int status, Bundle extras) { }
    public void onProviderEnabled(String provider) { }
    public void onProviderDisabled(String provider) { }
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1000, locationListener); 
}

Now i'm wondering if this is related to my code or my android device, or both. Tested Google maps and it trigger's the GPS icon and find my location without problem, i'm testing it on the android simulator now, will keep updated.

Oh and also, i'm unsing android studio.

Thank you.

EDIT: The GPS icon is triggered on the emulator, might be a setting in my phone, but what can cause this? And why do other GPS applications work?

EDIT 2 : My application works perfectly fine on the emulator, update the location via telnet geo fix and everything works like a charm..

Fortega
  • 19,463
  • 14
  • 75
  • 113

2 Answers2

0

This might not completely answer your question but it might help:

  1. For testing GPS related code I suggest you try http://www.genymotion.com/, it's the fastest Android emulator out there and it has a cool GPS testing widget, it's totally worth it (There is a free version).
  2. Make sure you have the correct Android permissions i.e. ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION
  3. Note that your LocationListener will only exist while the activity is running. This is probably not something you want, you should probably consider registering for position changes someplace else.
  4. Also try logging the results from onStatusChanged, onProviderEnabled, onProviderDisabled and see if there is any relevant information there.
  5. Finally, take a look at this question LocationListener of NETWORK_PROVIDER is enabled but , onLocationChanged is never called
Community
  • 1
  • 1
fernandohur
  • 7,014
  • 11
  • 48
  • 86
0

There may be a pretty simple solution and I'm sorry when you've already considered this, but restarting the phone sometimes does the magic for me.

A little explanation: I worked for a couple of months on a location aware service and I was stumbling upon those kind of errors as well. It seems that at some point Google updates it's libraries in the background and only a restart can make it work again then. I had 6 Nexus5 phones with the exact same errors and a restart did the job for all of them.

Stefan Medack
  • 2,731
  • 26
  • 32