Android Push Notification Permission

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JereMiami
Posts: 119
Joined: Mon Nov 03, 2014 12:17 am

Android Push Notification Permission

Post by JereMiami » Wed Oct 04, 2023 3:26 am

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?

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Android Push Notification Permission

Post by LiveCode_Panos » Wed Oct 04, 2023 8:15 am

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
--

JereMiami
Posts: 119
Joined: Mon Nov 03, 2014 12:17 am

Re: Android Push Notification Permission

Post by JereMiami » Wed Oct 04, 2023 12:59 pm

Panos-

After updating to 9.6.10, the code works as expected.

Thanks!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”