I had a problem calling the LocationListener function to call callback onLocationChanged () on my phone. When I run my code in the emulator, it works fine, the callback is called every time I fix geo.
When I run the application on my phone, nothing happens. The callback is never called. I have a location enabled by both GPS and Wireless in my settings. The application has all permissions, permissions for access permissions.
Also, when I call getLastKnownLocation () on the LocationManager, my application crashes. (However, only on my stupid phone). Even if I try to catch an exception that will lead to its failure, it is still just a failure, so I canโt even get information about what causes it to fail. This is very frustrating.
LocationManager.getBestProvider () returns GPS, and when I open Google maps, it finds my location in no time. What the hell is going on here? Is there any way to understand why it is crashing on my phone?
private void setupLocListener(){ Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); c.setAltitudeRequired(false); c.setBearingRequired(false); c.setSpeedRequired(false); c.setCostAllowed(false); lm.requestLocationUpdates(lm.getBestProvider(c,true), 0, 0, new LocationListener() { @Override public void onLocationChanged(Location arg0) { map.setLocation(arg0); } public void onProviderDisabled(String arg0) { } public void onProviderEnabled(String arg0) { } public void onStatusChanged(String arg0, int arg1, Bundle arg2) { } }); }
source share