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..
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.