Skip to content Skip to sidebar Skip to footer

Force Close On Android Location Permissions

I'm trying to get the user's location using Network as well as GPS. This is how my flow goes - Get LocationManager Check if Network_Provider is enabled If enabled, check for per

Solution 1:

requestPermissions() is asynchronous. By the time that method returns, you do not have permission yet. The user has not even been asked to grant you the permission by that time.

If you determine that you do not hold the permission, and you need to call requestPermissions(), you cannot try getting the location yet. You need to do that in onRequestPermissionsResult() at the earliest, when you are informed about whether the user granted you permission.

See this sample app to see how to request permissions and then request a location.

Solution 2:

Don't call locationManager.requestSingleupdate() in getLocation() method.

After requesting permission, override the onRequestPermissionResult() method. Within that method, you have to check the permission is granted or not.

If the permission is granted then call locationManager.requestSingleupdate().

Solution 3:

you Have to use this awesome library called Dexter which easily help you to handle asking for permission and do action if permission confirmed or if refused.

Post a Comment for "Force Close On Android Location Permissions"