Fix security exception (Nearby places not loading after permissions granted) (#1440)

* Update changelog.md

* Versioning for v2.7.0

* Add logging to onPermissionsRequestResult

* Request location updates onStatusChanged

* Copy onResume() actions into onPermissionsRequestResult

* Added getLastKnownLocation method and hooked it up to refreshView

* Remove unnecessary calls, add more logging

* Add check to prevent NPE

* Check that curLatLng exists before getting Mapbox instance

* Moar logging

* Make curLatLang clearer

* Not a good hack - put curLatLang into the bundle separately

* Add TODO

* Rename variables for clarity

* Check for Network Provider as well, tidy up getLKL()

* Add Javadocs

* Remove unnecessary method in onStatusChanged

* Add checkGPS comment

* Remove unnecessary logs

* Add TODO

* Call bundle.clear() before inserting CurLatLng
This commit is contained in:
Josephine Lim 2018-04-18 21:30:13 +10:00 committed by neslihanturan
parent 9a3b6fc964
commit 3b129a6ea4
4 changed files with 58 additions and 16 deletions

View file

@ -79,6 +79,23 @@ public class LocationServiceManager implements LocationListener {
Manifest.permission.ACCESS_FINE_LOCATION);
}
/**
* Gets the last known location in cases where there wasn't time to register a listener
* (e.g. when Location permission just granted)
* @return last known LatLng
*/
public LatLng getLKL() {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Location lastKL = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKL == null) {
lastKL = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
return LatLng.from(lastKL);
} else {
return null;
}
}
public LatLng getLastLocation() {
if (lastLocation == null) {
return null;
@ -249,6 +266,7 @@ public class LocationServiceManager implements LocationListener {
public enum LocationChangeType{
LOCATION_SIGNIFICANTLY_CHANGED, //Went out of borders of nearby markers
LOCATION_SLIGHTLY_CHANGED, //User might be walking or driving
LOCATION_NOT_CHANGED
LOCATION_NOT_CHANGED,
PERMISSION_JUST_GRANTED
}
}