nativescript-community / perms

An unified permissions API for NativeScript on iOS and Android.
https://nativescript-community.github.io/perms/
Apache License 2.0
12 stars 9 forks source link

Add POST_NOTIFICATIONS runtime permissions for Android 13 #12

Open 7ammer opened 2 years ago

7ammer commented 2 years ago

It seems like android 13 / SDK33 now requires permissions for notifications called POST_NOTIFICATIONS.

From reading the below link it looks like you need to declare the permission in the app's manifest file AND request permission at runtime: https://developer.android.com/develop/ui/views/notifications/notification-permission

Is it possible to add this permission to this package?

farfromrefug commented 2 years ago

@7ammer It is now added in latest version ('notification'). Also know that as of now you can also pass native android permissions directly to check and request like "android.permission.POST_NOTIFICATIONS". That way you dont need to wait for me implement it anymore ;)

7ammer commented 2 years ago

Hi @farfromrefug, thanks for implementing this and for the tip! I seem to be running into an issue where the response from request is always [ 'never_ask_again', true ]. I've tried uninstalling the app to reset any user set permissions but nothing changes. I am using an emulator running sdk33.

farfromrefug commented 2 years ago

@7ammer i had the same issue. You need to ensure your targetSdkVersion is 33. I think same for compileSdkVersion

shiv19 commented 1 year ago

@farfromrefug Yes, after using targetSdkVersion 33 it is working as expected. How do we show the permission request reason? I tried passing the message as a string to the requestOptions param like so,

nscRequestPermission(
   'notification',
   '<reason_text_here>'
)

am I missing something?

farfromrefug commented 1 year ago

@shiv19 i dont see the native api to do so. Can you share a link?

shiv19 commented 1 year ago

Ah yes you're right. There is no api support for it. They recommend using a separate screen for it. Thanks! https://developer.android.com/develop/ui/views/notifications/notification-permission#request-in-context