Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Push notifications on Android do not arrive #209

Closed
steunobravo opened this issue Apr 29, 2023 · 8 comments
Closed

[Bug]: Push notifications on Android do not arrive #209

steunobravo opened this issue Apr 29, 2023 · 8 comments
Labels

Comments

@steunobravo
Copy link

steunobravo commented Apr 29, 2023

Which Platforms?

Android

Which React Native Version?

0.70.8

Which @braze/react-native-sdk SDK version?

4.1.0

Repro Rate

100%

Steps To Reproduce

After adding to the Braze project, when from the Tool of Expo notifications (https://expo.dev/Notifications) I try to send a notification on an Android device, the device does not receive the push notification.
If, on the other hand, I remove the Braze dependencies and try to send a notification, the device receives notifications again.

  • "@braze/expo-plugin": "^1.1.1"
  • "@braze/react-native-sdk": "^4.1.0"

Expected Behavior

Even after setting braze, notifications must continue to work the same.

Actual Incorrect Behavior

Android devices do not receive notifications

Verbose Logs

Braze v24.3.0 .Braze FirebaseMessagingService( 1683): Remote message did not originate from Braze. Not consuming remote message: com.google.firebase.messaging.RemoteMessage

Additional Information

No response

@radixdev
Copy link

radixdev commented May 1, 2023

  1. Can you provide full verbose logs of a reproduction of the issue?
  2. Can you provide a link to the Braze push campaign used to test?
  3. Are you sending push from Braze directly or from another source?
  4. If you need to receive push from non Braze sources as well, you need to follow https://www.braze.com/docs/developer_guide/platform_integration_guides/android/push_notifications/android/integration/standard_integration/#using-your-own-firebase-messaging-service.

@steunobravo
Copy link
Author

I have no other logs in addition to what I shared.
The problem is not the push notifications sent by Braze but my problem is when I try to receive push from non -Braze Sources. I use default FirebaseMessaging.

In fact, I believe that point 4 you indicated me, it could do to my case. But I can't understand where to put the code on Expo. It could be that I have to put it on node_modules/Expo-Notifications/Android/Src/Main/Java/Expo/Modules/Notifications/Service/ExpoFirebaseMessaginvice.kt?

@radixdev
Copy link

radixdev commented May 3, 2023

Yes, due to how Android manifests route intents, you'd need to override whatever other Firebase Messaging Service is registered in the manifest in order to route Braze specific intents to it.

@steunobravo
Copy link
Author

Ok, I modified expafirebasemessaginivice.kt from:
`package expo.modules.notifications.service

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import expo.modules.notifications.service.interfaces.FirebaseMessagingDelegate

open class ExpoFirebaseMessagingService : FirebaseMessagingService() {
protected open val firebaseMessagingDelegate: FirebaseMessagingDelegate by lazy {
expo.modules.notifications.service.delegates.FirebaseMessagingDelegate(this)
}

override fun onMessageReceived(token: String) = firebaseMessagingDelegate.onMessageReceived(remoteMessage)
override fun onNewToken(token: String) = firebaseMessagingDelegate.onNewToken(token)
override fun onDeletedMessages() = firebaseMessagingDelegate.onDeletedMessages()
}
`

to:
`package expo.modules.notifications.service

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import expo.modules.notifications.service.interfaces.FirebaseMessagingDelegate
import com.braze.push.BrazeFirebaseMessagingService

open class ExpoFirebaseMessagingService : FirebaseMessagingService() {
protected open val firebaseMessagingDelegate: FirebaseMessagingDelegate by lazy {
expo.modules.notifications.service.delegates.FirebaseMessagingDelegate(this)
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
if (BrazeFirebaseMessagingService.handleBrazeRemoteMessage(this, remoteMessage)) {
// This Remote Message originated from Braze and a push notification was displayed.
// No further action is needed.
} else {
// This Remote Message did not originate from Braze.
// No action was taken and you can safely pass this Remote Message to other handlers.
firebaseMessagingDelegate.onMessageReceived(remoteMessage)
}

}
override fun onNewToken(token: String) = firebaseMessagingDelegate.onNewToken(token)
override fun onDeletedMessages() = firebaseMessagingDelegate.onDeletedMessages()
}
`

I tried to send a notification from Expo push notifications Tools (URL) but I don't receive it.

What am I doing wrong?

@radixdev
Copy link

radixdev commented May 5, 2023

  1. I would add logging and verify that things are being called as you expect. This code looks correct.
  2. I would add that logging in this issue to verify
  3. I would also ensure that the Braze firebase service isn't still registered in your manifest if you're using another service.

@ertemishakk
Copy link

@steunobravo make sure you're on the latest android version and have added POST_NOTIFICATIONS in your manifest
https://developer.android.com/develop/ui/views/notifications/notification-permission

@steunobravo
Copy link
Author

Yes I had already POST_NOTIFICATIONS in my manifest:
`

<receiver
  android:name=".service.NotificationsService"
  android:enabled="true"
  android:exported="false">
  <intent-filter android:priority="-1">
    <action android:name="expo.modules.notifications.NOTIFICATION_EVENT" />

    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.REBOOT" />
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />

    <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
  </intent-filter>
</receiver>

<service
  android:name="com.braze.push.BrazeFirebaseMessagingService"
  android:exported="false">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>

<activity android:name=".service.NotificationForwarderActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"
  android:excludeFromRecents="true"
  android:noHistory="true"
  android:launchMode="standard"
  android:taskAffinity=""
  />
`

Is it possible that I need to configure the Braze SDK with a different Firebase project than the one used by Expo?

@hokstuff
Copy link
Collaborator

Since this issue is more directly associated with the Expo plugin, I am closing out this issue as a dupe of this ticket in our Expo repo. Please continue to converse on that ticket to ensure that nothing gets lost in the mix - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants