Xamarin.Forms-Android:永远不会调用OnRequestPermissionsResult

时间:2018-10-18 07:32:35

标签: xamarin xamarin.forms permissions android-permissions

在Android下,我需要一些权限才能使用Google-Map API。我使用PermissionsPlugin:

https://www.nuget.org/packages/Plugin.Permissions/

这里有一些代码:

async void RequestPermissions()
{
    var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
    if (status != PermissionStatus.Granted)
    {
        if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
        {
            //NavigationHelper.CurrentPage.DisplayAlert("Need location", "Gunna need that location", "OK");
        }

        var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

        //Best practice to always check that the key exists
        if (results.ContainsKey(Permission.Location))
            status = results[Permission.Location];
    }
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
    PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    //base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

但是我还注意到,从未调用过“ OnRequestPermissionsResult”方法,并且没有对话框向我询问权限!

此外,权限也位于清单文件中!

有什么办法解决这个问题吗?

0 个答案:

没有答案