I want to access fine location from within my app and, for this, I declare an ActivityResultLauncherwith :
protected final ActivityResultLauncher<String[]> l = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), isGranted -> {
if (isGranted .get(Manifest.permission.ACCESS_COARSE_LOCATION) & isGranted .get(Manifest.permission.ACCESS_FINE_LOCATION)) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, positionChangesListener);
} else {
Toast.makeText(this, getResources().getText(R.string.PermissionNotAllowed), Toast.LENGTH_LONG).show()
finish();
}
});
When I want to ask for this permission, I use :
l.launch(new String [] {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
Unfortunately, the panel asking the user to grant permission doesn't show up. This doesn't prevent the callback from being executed, but with permissions denied. My app then immediatly stops, informing the user it can't continue to work if fine location permission isn't granted.
Any idea which could solve my problem?