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

How to trigger a deep link from a local notification? #485

Open
shimatai opened this issue Jul 31, 2017 · 9 comments
Open

How to trigger a deep link from a local notification? #485

shimatai opened this issue Jul 31, 2017 · 9 comments

Comments

@shimatai
Copy link

Hi,

How can I trigger a deep link from a FCM.presentLocalNotification?

I'm using React Native 0.45.0 with react-native-fcm 7.0.3 and I'm running in a real Android device and in an emulator too.

All notifications are working well, but I didn't find a way to load a deep link when the user press on the local notification (showed on the Android notification bar).

@justuseapen
Copy link
Contributor

justuseapen commented Aug 1, 2017

I'm working on this now. You can use the notification listener to grab notification details and use your router (in my case react-native-router-flux) to trigger the desired action and show the right view.

If you're using URL schemes seems like Crossroads is the routing lib of choice for projects like this.

@shimatai your thumbs up indicates this maybe solved your issue. Is that the case? If so, @evollu you can probably close this.

@shimatai
Copy link
Author

The notification listener doesn't works as I expect, because I want to route to a screen only if the user clicks on the message in the notification bar.

Actually, when app receives a push notification and user clicks on notification, nothing happens.

I know that notification listener can route to a screen, but I want to route only if the user clicks on Android notification bar.

@evollu
Copy link
Owner

evollu commented Sep 15, 2017

@shimatai you can check if the notif has opened_from_tray

@shimatai
Copy link
Author

@evollu

If the user receives a push notification with the app closed, the registered listener is not being triggered.

What's the solution for this issue? Is there anyway to trigger a method in my app when receiving a push notification with the app closed?

@evollu
Copy link
Owner

evollu commented Sep 15, 2017

put the listener outside of the component lifecycle, just like what readme does.

@shekharskamble
Copy link

@shimatai - did you manage to resolve this? if yes then how?

@shimatai
Copy link
Author

shimatai commented Mar 6, 2018

@shekharskamble I had to create a Java class that extends com.evollu.react.fcm.MessagingService and then you have to override onMessageReceived method.

For example:

import com.evollu.react.fcm.MessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Set;

public class MyAppMessagingService extends MessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Set<String> keys = remoteMessage.getData().keySet();
        for (String key : keys) { // List all keys inside incoming message
            Log.i("MyAppMessagingService", "Key " + key + ": " + remoteMessage.getData().get(key));
        }
        super.onMessageReceived(remoteMessage);
    }
}

@shekharskamble
Copy link

@shimatai - thanks for the example but how are you triggering deep link from onMessageReceived?

@shimatai
Copy link
Author

shimatai commented Apr 4, 2018

@shekharskamble No, that piece of code is in the native side (it's a Java class that extends the MessagingService of react-native-fcm).

This code is to receive a push notification when the app is closed (not in background nor in use). In my case, when the app receives a notification, my app saves the content in a key (that is read by React Native's AsyncStorage when the app is launched again).

I had to do this because my users can receive notifications while not using the app and the listener written in JavaScript is not triggered.

The deep link is triggered by react-native-fcm. I didn't need to register a deep link.

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

No branches or pull requests

4 participants