Unity-Technologies / com.unity.mobile.notifications

Mobile Notifications Package
https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.1/manual/index.html
Other
131 stars 42 forks source link

Mobile push notifications 2.1.0 not working on samsung devices running android 12 #231

Closed EoghanGallagher closed 1 year ago

EoghanGallagher commented 1 year ago

Hi .

I have a unity app that uses mobile push notifications 2.1.0 .

I have the correct permissions set for android devices running android 12 ( SCHEDULE_EXACT_ALARM ) . Actually I have the schedule_at_exact_time drop down set to everything .

The notifications run perfectly on a moto g62 and a google pixel 4 running android 12 .

However on a samsung note 10+ running android the notifications are inconsistent or don't fire at all . This occurs on multiple samsung devices

Am i missing something!!

aurimasc commented 1 year ago

Try looking into settings and what permissions are granted for your app. The permission to schedule exact alarm does not guarantee your app will be able to, that still can be disabled in settings.

Mirkobil commented 1 year ago

same here Mobile Notification 2.1.0, "Schedule at exact time" set to "Everthing" works on all phones except samsung android 12.. On samsung galaxy s10 android 11 everything works fine, after updating to 12 everything stopped.. on samsung s22 ultra notifications work partially.. some fire some don't.. app notification permissions are fully granted on settings panel

EoghanGallagher commented 1 year ago

@Mirkobil So I had a look at the settings on Samsung note 10 Plus.

I went to App -> my app -> Battery and then selected Unrestricted. I checked ADB and noted that my app is now on the doze white list .

adb shell dumpsys deviceidle

Selecting the other options Optimized and Restricted removed the app from the whitelist.

Notifications work fine even in battery saver mode when Unrestricted is selected

I encountered a new issue though on the Samsung galaxy a13 .

I scheduled some test notifications. Then I enabled battery saver mode with all options selected. Turned it off again . The notifications never fired even with battery saver mode turned off.

EoghanGallagher commented 1 year ago

What's the best approach for getting you app white listed ?

Should I implement it myself ? I.E request REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permissons an then attempt to add my app to the whitelist via code . Present the user with a prompt to allow the app to run in the background or grant unrestricted access to the battery?

xiabob commented 1 year ago

maybe "App hibernation" issue?

leehans commented 1 year ago

Hi, we're currently experiencing very similar (if not exactly similar) issues on some of our Samsung devices. Both running on Android 12+ (in fact, one is running Android 13).

Any updates to this issue?

EoghanGallagher commented 1 year ago

@leehans In the end I built a little android plugin that toggled the battery optimization on and off. Basically just removes and adds the app to the doze whitelist

In unity I added a ui popup that explained and asked the user for permission to set the app to battery unrestricted mode

Once the app is unrestricted all notifications for my app worked fine on Samsung devices running android 12+ and android 13.

Hope that helps

aurimasc commented 1 year ago

A set of APIs was introduced to request permission to schedule at exact times and bypass battery optimizations.