[英]How to ask authorization for save image in Gallery on Android using Xamarin?
I need to save a screenshot capture in the user gallery but the authorization is not automatically asked.我需要在用户库中保存屏幕截图,但不会自动询问授权。 I allowed permission in the Android manifest (WRITE_EXTERNAL_STORAGE) but it doesn't ask it for, I have to set it in the emulator settings.我允许在 Android 清单 (WRITE_EXTERNAL_STORAGE) 中获得许可,但它没有要求,我必须在模拟器设置中进行设置。 Does someone know how to ask authorization, as the location?有人知道如何要求授权,作为位置吗?
You could use the plugin PermissionsPlugin from nuget .您可以使用 nuget 中的插件PermissionsPlugin 。
try
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>();
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await DisplayAlert("Need location", "Gunna need that location", "OK");
}
status = await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>();
}
if (status == PermissionStatus.Granted)
{
//Query permission
}
else if (status != PermissionStatus.Unknown)
{
//location denied
}
}
catch (Exception ex)
{
//Something went wrong
}
For more details you could check https://github.com/jamesmontemagno/PermissionsPlugin有关更多详细信息,您可以查看https://github.com/jamesmontemagno/PermissionsPlugin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.