Page 1 of 1

Android Push Notification Permission

Posted: Wed Oct 04, 2023 3:26 am
by JereMiami
I can get permissions for things like location services and the camera, but for the life of me I cannot get push notification permissions to pop up. Any help on why this is would be appreciated.

Code: Select all

   put androidHasPermission("android.permission.RECEIVE_WAP_PUSH") into tNotificationPermissionGranted
   if not tNotificationPermissionGranted then
      androidRequestPermission "android.permission.RECEIVE_WAP_PUSH"
   end if
   if not tNotificationPermissionGranted then
      answer "This app is not permitted to receive push notifications. You must change this in the settings app prior to using this app"
   end if
This code is within openCard on start up after requesting precise location permissions. Should it be somewhere else?

Re: Android Push Notification Permission

Posted: Wed Oct 04, 2023 8:15 am
by LiveCode_Panos
Hello JereMiami,

When building for API33 (i.e. with LiveCode 9.6.10 or 10.0.0 DP-6) and running on Android 13 and above, applications which send push notifications must check that the user has granted the necessary permission to do so and request it if not.

This could be done, for example, when the user enables an app feature which requires such notifications, or on startup of the app, in the app's main openStack handler, using the following code:

Code: Select all

if the platform is "android" and the systemVersion >= 13 then
   local tPostNotificationsPermissionGranted
   put androidHasPermission("android.permission.POST_NOTIFICATIONS") \
      into tPostNotificationsPermissionGranted
   if not tPostNotificationsPermissionGranted then
      androidRequestPermission "android.permission.POST_NOTIFICATIONS" 
   end if
   put androidHasPermission("android.permission.POST_NOTIFICATIONS") \ 
      into tPostNotificationsPermissionGranted
   if not tPostNotificationsPermissionGranted then
      answer "This app is not permitted to post notifications. You can change this" && \
         "in the Settings app."
   end if
end if
Also, make sure you check the Push Notification checkbox in the Android settings and provide the necessary settings.json file

Hope this helps.

Kind regards,
Panos
--

Re: Android Push Notification Permission

Posted: Wed Oct 04, 2023 12:59 pm
by JereMiami
Panos-

After updating to 9.6.10, the code works as expected.

Thanks!