Did you add the necessary code to your Activity's OnRequestPermissionsResult method?
Permission location Android Xamarin
Hello I have the following code to ask location on runtime for a Xamarin forms (Android)
var status = await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>();
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await Application.Current.MainPage.DisplayAlert("Need location", "Gunna need that location", "OK");
}
status = await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>();
}
But after the request alert pops up, the app gets stuck and I need restart it. after that works normally and don't ask for the permission again. I have added to the manifest btw thx in advance
2 answers
Sort by: Most helpful
-
-
Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
2021-03-10T02:49:58.197+00:00 Hello,
Welcome to Microsoft Q&A!
Try to change the code in
OnRequestPermissionsResult
method .From
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
to
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
And you have to install
Plugin.Permissions
package first .Refer to the thread : https://forums.xamarin.com/discussion/comment/352856/#Comment_352856.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.