简体   繁体   中英

Open browser when clicked on fcm notification instead of opening launcher activity

I want to send url with FCM to android application. Is it possible to open browser when clicked on FCM notification instead of opening launcher activity? I know it possible with overriding onMessageReceived() method but i don't want do it. I checked the click_action parameter in payload but as Firebase said:

If specified, an activity with a matching intent filter is launched when a user clicks on the notification.

I'm try to add click_action in CustomData inside firebase cloudMessaging panel like this:

在此处输入图片说明

But it not working and open application instead.

I'm used postman to send notification for this purpose and add click_action to notification object like this:

在此处输入图片说明

Notification send to my device but when clicked on it, nothing happened!!!

Important: My apk released on GooglePlay and i can't change the source code of application.

Anybody help please.

when your app is in the background. the notification is delivered to the device's system tray. A user tap on a notification opens the app launcher by default.

if the message has data, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

so you can according to different data, to handle the condition.

  1. Set click_action in the notification payload
{
  ...
  "notification": {
      "click_action": "activity action"
  },
 ....
}

2.in the mainfest you have to config the inter fliter.

<intent-filter>
  <action android:name="some action" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

then when you click it, it will open that action activity. here is the document descirbe:

the If specified, an activity with a matching intent filter is launched when a user clicks on the notification.

so I think you try to set the click_action acton to match the browser chooser action, or "Intent.ACTION_VIEW" and data set like that "http://"

I hope that can give you some help

Pass Intent of setData in PendingIntent.

Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));

PendingIntent pending = PendingIntent.getActivity(this, 0, notificationIntent, 
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.setContentIntent(pending);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM