简体   繁体   English

Xamarin.forms android权限提示不显示

[英]Xamarin.forms android permission prompt not displaying

I am using the permission plugin by James Montemagno. 我正在使用James Montemagno的权限插件

I basically copied the example however the permission is unknown after the line to request it. 我基本上复制了示例,但是在请求它的行之后,权限是未知的。 No dialog even shows. 甚至没有对话框显示。

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

                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });
                status = results[Permission.Location];
            }
            if (status == PermissionStatus.Granted)
            {
                //var results = await CrossGeolocator.Current.GetPositionAsync(10000);
                //LabelGeolocation.Text = "Lat: " + results.Latitude + " Long: " + results.Longitude;
            }
            else if (status != PermissionStatus.Unknown)
            {
                await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
            }
            Debug.WriteLine("Location permission: {0}", status);

I have the Permissions in my android manifest. 我的Android清单中有Permissions。 This problem only started showing once I updated my target platform to 6.0+ 我将目标平台更新到6.0+后,此问题才开始显示

I also added this to my MainActivity 我也将此添加到了MainActivity

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
        {
            PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }

This question is different since it has nothing to do with maps. 这个问题有所不同,因为它与地图无关。 I cannot use any real time permission since the prompts are simply not showing within the application. 我不能使用任何实时权限,因为提示根本没有显示在应用程序中。

Some how MainApplication.cs was not installed along with the plugin. 一些未与插件一起安装MainApplication.cs的方式。 It was put in the correct directory but I had to manually add it to the project. 它被放置在正确的目录中,但是我不得不手动将其添加到项目中。 Not really sure why that occurred but there you go. 不太确定为什么会这样,但是您去了。

In my case the MainApplication.cs is not added in my Android Project. 在我的情况下, MainApplication.cs未添加到我的Android项目中。 The better way that i used is to uninstall the CurrentActivity Plugin along with all the NUgets that depend on it. 我使用的更好的方法是卸载CurrentActivity Plugin以及所有依赖它的NUgets I again install CurrentActivity Plugin and all other plugins. 我再次安装CurrentActivity Plugin和所有其他插件。 Now the MainApplication.cs is in the root directory of the Android project. 现在MainApplication.cs位于Android项目的根目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM