Im trying to make my app open a link in the browser when a notification is recieved, but cant find a method that works with the app in foreground and in background.
The notification looks like this
"notification": {
"title": "My app try",
"body": "This is a notification, YAY!",
},
"data": {
"code":"1003",
"url":"https://www.thisishard.com"
}
If the app is closed I need to show the notification and when the user clicks on it, open the app and then open the browser.
But if the app is opened, I need to show the notification and only open the browser if the user clicks it.
Now it just opens the browser no metters what if the app is open and just opens the app if it is closed.
Im using firebase cloud messaging to send the notifications.
EDIT:
What I do is, in the onMessageReceived(), use an Intent to open the web browser
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String intentUri = remoteMessage.getData().get("url");
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentUri));
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(browserIntent);
}