yayaa / LocationManager

Simplify getting user's location for Android
806 stars 187 forks source link

onPermissionGranted not called #57

Closed rmtheis closed 7 years ago

rmtheis commented 7 years ago

First off, this project is excellent! It has saved me a ton of time, so thank you for that.

I'm having an issue with onPermissionGranted not being called when I choose "Allow" in the permission dialog.

onPermissionGranted is called the second time I call locationManager.get(), but that method is not called the first time I call locationManager.get(), when the user taps "Allow" on the dialog.

Does this look like a bug to you, or am I doing something wrong?

I'm using version 2.0.3.

The complete code is here: https://github.com/rmtheis/LocationManagerTestApp

Configuration

        LocationConfiguration locationConfiguration = new LocationConfiguration.Builder()
                .askForPermission(new PermissionConfiguration.Builder().rationaleMessage("rationale...").build())
                .useGooglePlayServices(new GooglePlayServicesConfiguration.Builder().build())
                .useDefaultProviders(new DefaultProviderConfiguration.Builder().gpsMessage("gps").build())
                .build();

        locationManager = new LocationManager.Builder(getApplicationContext())
                .activity(this)
                .configuration(locationConfiguration)
                .notify(this)
                .build();

Logs

06-18 16:54:07.093 12234-12234/com.rmtheis.locationmanagertestapp I/DefaultPermissionProvider: Should show rationale dialog for required permissions: false
06-18 16:54:07.093 12234-12234/com.rmtheis.locationmanagertestapp I/DefaultPermissionProvider: Asking for Runtime Permissions...
06-18 16:54:07.114 12234-12234/com.rmtheis.locationmanagertestapp I/LocationManager: Waiting until we receive any callback from PermissionProvider...
yayaa commented 7 years ago

Hey @rmtheis ,

You don't need to ask for permission before calling locationManager.get() since you define PermissionConfiguration in your builder, library will handle that parr too. Just remove the part you ask for permission manually, and library will call onPermissionGranted first time user grants as well.

rmtheis commented 7 years ago

Hmm...I'm not sure what you mean. I'm not asking for permission manually, I just see the permission prompt the first time that I call to locationManager.get(). It's at that point that I'm expecting onPermissionGranted() to be called, but I'm not seeing that happen.

yayaa commented 7 years ago

Ahhh, sorry misunderstand the problem.

I just saw your sample code, it is because you are not extending LocationBaseActivity nor calling the required methods. So that library cannot work properly and retrieve or pass back the related information.

This library requires quite a lot of lifecycle information to handle all the steps between onCreate - onResume - onPause - onDestroy - onActivityResult - onRequestPermissionsResult.

Please read the README file for further information.

rmtheis commented 7 years ago

Thank you! Not sure how I overlooked that.