admin管理员组文章数量:1394051
I have a .NET MAUI Android Application and I am debugging on a physical device with Android 14.0 - API 34
Now in my AndroidManifest.xml
I have the line <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
I am expecting that on application startup the user will be requested to accept or decline push notifications.
But just NOTHING happens...
I need to manually request the permission like described here
So what I am doing currently in my App.xaml.cs
is:
protected override async void OnStart()
{
await CheckAndRequestPushNotificationsPermission();
}
public static async Task<PermissionStatus> CheckAndRequestPushNotificationsPermission()
{
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.PostNotifications>();
if (status == PermissionStatus.Granted)
return status;
if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
{
// Prompt the user to turn on in settings
// On iOS once a permission has been denied it may not be requested again from the application
return status;
}
if (Permissions.ShouldShowRationale<Permissions.PostNotifications>())
{
// Prompt the user with additional information as to why the permission is needed
}
status = await Permissions.RequestAsync<Permissions.PostNotifications>();
return status;
}
This works now but I have questions:
- Why do I need the
uses-permission
inside myAndroidManifest.xml
when I need to request it manually anyway? - When I initially start the App the PermissionStatus is
Denied
and I get asked if I want to enable. When I deny the status does not change... so why am I not getting asked over and over again? - Is that the right way to do it?
I have a .NET MAUI Android Application and I am debugging on a physical device with Android 14.0 - API 34
Now in my AndroidManifest.xml
I have the line <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
I am expecting that on application startup the user will be requested to accept or decline push notifications.
But just NOTHING happens...
I need to manually request the permission like described here
So what I am doing currently in my App.xaml.cs
is:
protected override async void OnStart()
{
await CheckAndRequestPushNotificationsPermission();
}
public static async Task<PermissionStatus> CheckAndRequestPushNotificationsPermission()
{
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.PostNotifications>();
if (status == PermissionStatus.Granted)
return status;
if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
{
// Prompt the user to turn on in settings
// On iOS once a permission has been denied it may not be requested again from the application
return status;
}
if (Permissions.ShouldShowRationale<Permissions.PostNotifications>())
{
// Prompt the user with additional information as to why the permission is needed
}
status = await Permissions.RequestAsync<Permissions.PostNotifications>();
return status;
}
This works now but I have questions:
- Why do I need the
uses-permission
inside myAndroidManifest.xml
when I need to request it manually anyway? - When I initially start the App the PermissionStatus is
Denied
and I get asked if I want to enable. When I deny the status does not change... so why am I not getting asked over and over again? - Is that the right way to do it?
- 1 Documentation – tomerpacific Commented Mar 27 at 13:30
- Yeah ok it is required in the AppManifest. I was already that far – CrazyEight Commented Mar 27 at 13:40
1 Answer
Reset to default 1Why do I need the uses-permission inside my AndroidManifest.xml when I need to request it manually anyway?
The uses-permission
in the AndroidManifest.xml is used to declare the permissions your app need. And the official document about Declaring app permissions said:
if your app requests app permissions, you must declare these permissions in your app's manifest file. These declarations help app stores and users understand the set of permissions that your app might request.
And the POST_NOTIFICATIONS
is a runtime permission. The official document about Request runtime permissions said:
If you declare any dangerous permissions, and if your app is installed on a device that runs Android 6.0 (API level 23) or higher, you must request the dangerous permissions at runtime
so why am I not getting asked over and over again?
This is because you only called the Permissions.RequestAsync<Permissions.PostNotifications>();
once. And the code executed finished after user operation. For more information, you can check the official document about App capabilities depend on user choice in permissions dialog.
But if user denies the permission more than once, the request dialog will not show any more. The official document about Handle permission denial said:
Starting in Android 11 (API level 30), if the user taps Deny for a specific permission more than once during your app's lifetime of installation on a device, the user doesn't see the system permissions dialog if your app requests that permission again. The user's action implies "don't ask again." On previous versions, users saw the system permissions dialog each time your app requested a permission, unless they had previously selected a "don't ask again" checkbox or option.
本文标签: cMAUIAndroidManifest usespermission no requestStack Overflow
版权声明:本文标题:c# - MAUI - AndroidManifest uses-permission no request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744087151a2588735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论