braze-inc / braze-react-native-sdk

Public repo for the Braze React Native SDK
https://www.braze.com
Other
64 stars 83 forks source link

[Android] - Push notifications don't work on Android 13 #157

Closed edusantos-livup closed 2 years ago

edusantos-livup commented 2 years ago

Hi, I've update the appboy-react-sdk to 1.36.0 to support Braze Android SDK 21.0.0 because I've received an email from Braze saying that starting from Android 13 the push notification permission will change.

I've followed this Braze Migration Guide and started my RN application on an Android 13 (API 33) emulator from Android Studio. Then, I've sent a push notification from the Braze dashboard panel, but I didn't received any push notification on this emulator (not even a native message to allow push notification permission). Previously I did the same with another emulator running Android 12 and I received the push notification properly.

Am I missing something or is it not still working properly for Android 13?

bryanlogan commented 2 years ago

Are you obtaining the push permission first from the user? We don't automatically prompt for push if it's not allowed. You may want to reach out to support@braze.com so we can discuss this with logcats and other information that we don't want to put on GitHub.

edusantos-livup commented 2 years ago

How can I obtain the push permission from the user? I though that only by updating the SDK it will be asked to the user automatically after receiving the first push notification on the device...

bryanlogan commented 2 years ago

You'll send an InApp Message to display it. See https://www.braze.com/docs/user_guide/message_building_by_channel/push/push_primer_messages/

edusantos-livup commented 2 years ago

I've sent this InApp message suggested by you, but when I click on the “Allow notifications” button with the “Request Push Permission” action nothing happens...

bryanlogan commented 2 years ago

Please send logcats to support@braze.com so we can further investigate.

edusantos-livup commented 2 years ago

@bryanlogan, how should it works if I'm targeting Android 12, updated to the last appboy-react-sdk version and open my app on an Android 13 emulator? I thought that the correct behavior would be opening automatically the Android native prompt to accept the Push permission when receiving the first push from Braze or when opening my App for the first time, and nothing it's happening... I don't want to use the "Push Permier Messages" feature because I want to keep my app targeting Android 12 for the moment.

The full information about the behavior targeting Android < 13 is here and this is not working with appboy-react-sdk:

If your app targets 12L (API level 32) or lower, the system shows the permission dialog the first time your app starts an activity after you create a notification channel, or when your app starts an activity and then creates its first notification channel. This is usually on app startup.

radixdev commented 2 years ago

Hi @edusantos-livup ,

edusantos-livup commented 2 years ago

@radixdev , the documentation you sent said clearly that it's possible to receive push notifications targeting Android <= 12 on an Android 13 device. The permission dialog is shown the first time the app starts an activity with notification channel. The Braze documentation says that a default notification channel is created when a push notification is received.

Google oficial documentation quote:

If your app targets 12L (API level 32) or lower, the system shows the permission dialog the first time your app starts an activity after you create a notification channel, or when your app starts an activity and then creates its first notification channel. This is usually on app startup.

Braze official documentation quote:

Note: Braze automatically creates a default notification channel if one does not already exist when a push notification is received. If you don’t target Android 13, this will cause the push permission prompt to be shown, which is required to show the notification.

radixdev commented 2 years ago

Hi @edusantos-livup ,

We did a deep dive into the code and can verify this was a bug on our end, specifically for your target = Android 12 & device = Android 13 . As a workaround I would suggest creating a notification channel if one does not exist already in your Application.onCreate(). We will have a fix available in the core SDK and react afterwards to address this.

radixdev commented 2 years ago

Hi @edusantos-livup ,

We've addressed this in the core Braze android sdk in release 23.0.0. We will be updating this repo to use that version soon.

edusantos-livup commented 2 years ago

Thanks @radixdev . Do you know when the appboy-react-sdk will target the Android SDK 23.0.0?

radixdev commented 2 years ago

The upgrade is currently in review. We will update you once it's released.

Minishlink commented 2 years ago

Hello, I'm using Android SDK 23.0.1 and this does not seem to be fixed.

The workaround of creating a notification channel in Application.onCreate works only partially, although that seems to be an Android's limitation: the permission request appears on the second start of the app, not the first.

radixdev commented 2 years ago

Hi @Minishlink ,

Can we get your android API target level, device used for testing, and API version of said device?

Minishlink commented 2 years ago

Emulator Android API level 33 Android API target level 31

radixdev commented 2 years ago

Hi @Minishlink ,

I cannot reproduce with your API levels on SDK version 23.0.1. Can you provide verbose logs starting from the app launch to a notification channel not being created?

Minishlink commented 2 years ago

Hello, here are some logs:

fecycleCallbackListener  V  BrazeActivityLifecycleCallbackListener using in-app messaging blocklist: []
                         V  BrazeActivityLifecycleCallbackListener using session handling blocklist: []
   Braze v23.0.1 .Braze  V  The instance is null. Allowing instance initialization
                         D  Braze SDK Initializing
DefaultBrazeImageLoader  D  Initializing disk cache
   Braze v23.0.1 .Braze  D  Braze SDK loaded in 32 ms.
DefaultBrazeImageLoader  D  Disk cache initialized
   Braze v23.0.1 .Braze  D  Applying any pending runtime configuration values
   Braze v23.0.1 .Braze  I  Firebase Cloud Messaging found. Setting up Firebase Cloud Messaging.
   Braze v23.0.1 .Braze  I  Automatic ADM registration not enabled in configuration. Braze will not register for ADM.
       Braze v23.0.1 .l  D  Braze geofences not enabled. Geofences not set up.
      Braze v23.0.1 .l1  D  Did not find stored geofences.
      Braze v23.0.1 .l1  I  Geofences implicitly disabled via server configuration.
      Braze v23.0.1 .h0  V  recalculateDispatchState called with session state: NO_SESSION lastNetworkLevel: NONE
       Braze v23.0.1 .v  V  Capabilities changed. [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED LinkUpBandwidth>=12000Kbps LinkDnBandwidth>=30000Kbps Tran
      Braze v23.0.1 .h0  V  recalculateDispatchState called with session state: NO_SESSION lastNetworkLevel: GOOD
       Braze v23.0.1 .v  V  Capabilities changed. [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED LinkUpBandwidth>=12000Kbps LinkDnBandwidth>=30000Kbps Tran
      Braze v23.0.1 .h0  V  recalculateDispatchState called with session state: NO_SESSION lastNetworkLevel: GOOD
      Braze v23.0.1 .b1  D  Started offline event recovery task.
       Braze v23.0.1 .t  D  Getting the stored open session
      Braze v23.0.1 .l5  D  No stored open session in storage.
       Braze v23.0.1 .t  I  New session created with ID: 30347d98-42a5-486e-bd03-e65276d87639
      Braze v23.0.1 .z0  D  bo.app.e5 fired: SessionCreatedEvent(session=
      Braze v23.0.1 .y0  D  Session start event for new session received.
       Braze v23.0.1 .t  D  Checking if this session needs to be sealed: 30347d98-42a5-486e-bd03-e65276d87639
       Braze v23.0.1 .t  D  Checking if this session needs to be sealed: 30347d98-42a5-486e-bd03-e65276d87639
       Braze v23.0.1 .p  D  Not adding user id to event: {
      Braze v23.0.1 .k5  D  Adding event to storage with uid 3855158d-6af4-43e9-90ad-89d5cca582da
      Braze v23.0.1 .z0  D  bo.app.o0 fired: commandType = ADD_BRAZE_EVENT
       Braze v23.0.1 .o  I  Location collection disabled via sdk configuration.
       Braze v23.0.1 .p  V  Updated shouldRequestTriggersInNextRequest to: true
      Braze v23.0.1 .q6  V  Push token cache cleared.
      Braze v23.0.1 .k0  V  Device object cache cleared.
      Braze v23.0.1 .y0  D  Requesting trigger refresh.
      Braze v23.0.1 .z0  D  bo.app.o0 fired:             commandType = ADD_REQUEST
      Braze v23.0.1 .q0  V  Added request to dispatcher with parameters:
      Braze v23.0.1 .q0  V  SDK Auth is disabled, not adding token to request
       Braze v23.0.1 .p  V  Updated shouldRequestTriggersInNextRequest to: false
      Braze v23.0.1 .z0  D  bo.app.o0 fired:             commandType = ADD_REQUEST
      Braze v23.0.1 .q0  V  Added request to dispatcher with parameters:
      Braze v23.0.1 .z0  D  com.braze.events.SessionStateChangedEvent fired: SessionStateChangedEvent{sessionId='30347d98-42a5-486e-bd03-e65276d87639', eventType='SESSION_STARTED'}'
       Braze v23.0.1 .t  D  Cancelling session seal alarm
      Braze v23.0.1 .z0  D  bo.app.h5 fired: bo.app.h5@88ff165
      Braze v23.0.1 .h0  V  recalculateDispatchState called with session state: OPEN_SESSION lastNetworkLevel: GOOD
      Braze v23.0.1 .g0  D  Unable to find the xml INTEGER configuration value with primary key 'com_braze_data_flush_interval_good_network'.Using default value '30'.
      Braze v23.0.1 .h0  V  currentIntervalMs: 30000
      Braze v23.0.1 .k0  D  Cache locked successfully for export: bo.app.k0@a06daeb
      Braze v23.0.1 .q6  V  Push token cache cleared.
      Braze v23.0.1 .q0  D  Event dispatched: {"name":"ss","data":{},"time":1.661933680633E9,"session_id":"30347d98-42a5-486e-bd03-e65276d87639"} with uid: 3855158d-6af4-43e9-90ad-89d5cca582da
      Braze v23.0.1 .h0  D  Data flush interval has changed from -1 ms to 30000 ms after connectivity state change to: GOOD and session state: OPEN_SESSION
       Braze v23.0.1 .t  D  Checking if this session needs to be sealed: 30347d98-42a5-486e-bd03-e65276d87639
       Braze v23.0.1 .p  I  Completed the openSession call. Starting or continuing session 30347d98-42a5-486e-bd03-e65276d87639
       Braze v23.0.1 .q  D  Messaging session not started.
       Braze v23.0.1 .p  V  Opened session with activity: MainActivity
       Braze v23.0.1 .l  D  Braze geofences not enabled. Not requesting geofences.
      Braze v23.0.1 .q0  V  SDK Auth is disabled, not adding token to request
      Braze v23.0.1 .j3  D  Making request with id => "yyy"
                         D  "X-Braze-TriggersRequest" => "true"
                         D  "X-Braze-DataRequest" => "true"
                         D  "X-Braze-Api-Key" => "xxx"
      Braze v23.0.1 .j3  D  Making request with id => "yyyy"
                         D  "X-Braze-ContentCardsRequest" => "true"
                         D  "X-Braze-DataRequest" => "true"
                         D  "X-Braze-Api-Key" => "xxx"
      Braze v23.0.1 .r5  V  Enabling SSL protocols: [TLSv1, TLSv1.1, TLSv1.2, TLSv1.3]
      Braze v23.0.1 .r5  V  Enabling SSL protocols: [TLSv1, TLSv1.1, TLSv1.2, TLSv1.3]
      Braze v23.0.1 .j3  D  Result(id = db412aca23b0dbb8 time = 382ms)
      Braze v23.0.1 .z0  D  bo.app.w fired: bo.app.w@3cf3f7c
      Braze v23.0.1 .b0  D  ContentCardsSyncRequest executed successfully.
       Braze v23.0.1 .s  V  Processing server response payload for user with id:
      Braze v23.0.1 .a0  I  Updating offline Content Cards for user with id:
      Braze v23.0.1 .j3  D  Result(id = e8d938297918bafc time = 403ms)
       Braze v23.0.1 .d  V  Found 0 triggered actions in server response.
      Braze v23.0.1 .i0  D  DataSyncRequest executed successfully.
       Braze v23.0.1 .s  V  Processing server response payload for user with id:
      Braze v23.0.1 .a5  V  Finishing updating server config to bo.app.y4@a7e0005
      Braze v23.0.1 .z0  D  bo.app.z4 fired: ServerConfigReceivedEvent(serverConfig=bo.app.y4@a7e0005)
       Braze v23.0.1 .l  D  Geofences enabled server config value false received.
      Braze v23.0.1 .z0  D  bo.app.o6 fired: TriggeredActionsReceivedEvent(triggeredActions=[])
      Braze v23.0.1 .z0  D  bo.app.r4 fired: RequestNetworkSuccessEvent(request={
      Braze v23.0.1 .k0  V  Notifying confirmAndUnlock listeners for cache: bo.app.k0@a06daeb
      Braze v23.0.1 .q6  V  Notifying confirmAndUnlock listeners for cache: bo.app.q6@8610048
      Braze v23.0.1 .z0  D  com.braze.events.ContentCardsUpdatedEvent fired: ContentCardsUpdatedEvent{userId='', timestampSeconds=1661933681, isFromOfflineStorage=false, card count=0}
       Braze v23.0.1 .p  V  Updated shouldRequestTriggersInNextRequest to: false
      Braze v23.0.1 .k5  D  Deleting event from storage with uid 3855158d-6af4-43e9-90ad-89d5cca582da
      Braze v23.0.1 .a5  V  Attempting to unlock server config info.
      Braze v23.0.1 .i0  D  Trigger dispatch completed. Alerting subscribers.
      Braze v23.0.1 .z0  D  bo.app.b6 fired: TriggerDispatchCompletedEvent(request={
      Braze v23.0.1 .g1  V  Automatically obtained Firebase Cloud Messaging token: xxx-xxx-xxx-xxx
      Braze v23.0.1 .z0  V  Publishing cached event for class: class com.
radixdev commented 2 years ago

@edusantos-livup The React SDK includes Android SDK 23.0.1 as of React SDK version 1.38.0

@Minishlink The default notification channel is only created in instances where a push notification is received by the device and no channel is available to display it. The SDK does not pre-emptively create a channel before any push notification arrives to the device. Based on your logs and stated behavior, this looks like expected behavior.

Minishlink commented 2 years ago

That's odd, when Braze sends a notification and the push notification is received by the device, there's little chance that the app is open. The user might miss all notifications until he restarts the app and finally see the popup.