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

Integration with React Native Firebase V6. Initial Notification on Android is undefined #428

Closed
spaquis opened this issue Dec 23, 2019 · 15 comments

Comments

@spaquis
Copy link

spaquis commented Dec 23, 2019

Hi,
I integrate your librairy with react native firebase v6 (cloud messaging).
I receive the notification on Android, but when i click on it, the notification is undefined (PendingNotifications.getInitialNotification()) :
Initial notification was: N/A

I made no change on AndroidManifest.xml (Autolinking)
When app is opened, the "notificationOpenListener" work correctly

Could you help me ?
Thanks

@Aurelienlajoinie
Copy link

Got the same problem and have to add some native workaround to make it work :s

@spaquis
Copy link
Author

spaquis commented Dec 24, 2019

Hi @Aurelienlajoinie ,
Could you share your native workaround plz ?

@Aurelienlajoinie
Copy link

Aurelienlajoinie commented Jan 10, 2020

I use something like this in MainActivity.java:

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        // .....
        handleReactNativeNotifications();
    }
public void handleReactNativeNotifications() {
       Bundle intent = this.getIntent().getExtras();
       if (intent != null && (intent.getBoolean(LAUNCH_FROM_PUSH_FLAG) == true
           || intent.get("google.message_id") != null)) {
           WritableMap params =  Arguments.fromBundle(intent);
           sendEventToJavaScript(mReactInstanceManager.getCurrentReactContext(), NOTIFICATION_OPENED_EVENT_NAME, params);
       }
   }

And the flag is set in my custom PushNotification class:

public class FirebaseCloudMessagingPushNotification extends PushNotification {
    public FirebaseCloudMessagingPushNotification(Context context, Bundle bundle, AppLifecycleFacade appLifecycleFacade, AppLaunchHelper appLaunchHelper, JsIOHelper jsIoHelper) {
        super(context, bundle, appLifecycleFacade, appLaunchHelper, jsIoHelper);
    }

    @Override
    protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
        final Resources resources = mContext.getResources();
        Bundle intentBundle =  mNotificationProps.asBundle();
        RemoteMessage remoteMessage = new RemoteMessage(intentBundle);
        final Notification.Builder builder = super.getNotificationBuilder(intent);

        // Set Notification content
        builder.setContentTitle(remoteMessage.getNotification().getTitle());
        builder.setContentText(remoteMessage.getNotification().getBody());

        Intent notificationIntent = new Intent(mContext, MainActivity.class);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        notificationIntent.putExtras(intentBundle);
        notificationIntent.putExtra(LAUNCH_FROM_PUSH_FLAG, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent,
                PendingIntent.FLAG_ONE_SHOT);
        builder.setContentIntent(pendingIntent);

        return builder;
    }
}

Hope it helps someone :)

@spaquis
Copy link
Author

spaquis commented Jan 10, 2020

Thanks for sharing this @Aurelienlajoinie . I finally decided to downgrade react native firebase to v5 but I will try your solution on a sample project :)

@efstathiosntonas
Copy link

efstathiosntonas commented Jan 28, 2020

@Aurelienlajoinie can you please share the whole MainActivity.java or the whole files/classes?

@Aurelienlajoinie
Copy link

@efstathiosntonas my workaround doesn't work anymore with version 3.1.1 :s i have to find another solution.

@efstathiosntonas
Copy link

Thanks, if you manage to find a solution it would be great to post it here :)

@nates-dennis
Copy link

have the same issue selecting a notification from cold start launches the app but gives a null initial notification

@stale
Copy link

stale bot commented Mar 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Mar 7, 2020
@LRNZ09
Copy link

LRNZ09 commented Mar 12, 2020

I also have this issue with version 3.1.2

@stale stale bot removed the 🏚 stale label Mar 12, 2020
@stevenyap
Copy link

I also have this issue on version 3.1.2

1 similar comment
@abhaynpai
Copy link

I also have this issue on version 3.1.2

@abhaynpai
Copy link

@efstathiosntonas - Were you able to come up with a solution to this issue?

@stale
Copy link

stale bot commented Apr 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Apr 25, 2020
@stale
Copy link

stale bot commented May 2, 2020

The issue has been closed for inactivity.

@stale stale bot closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants