I want to send a specific link in the notification and send the notification through firebase push notification. What should I do?

Suppose that in my notification, today is x's birthday. It will open the FB link of X when clicking the notification. The same is true for y. how to use firebase to operate

resolvent:

Here's how to do this:

1) Request from server site:

Required website: https://fcm.googleapis.com/fcm/send

Method: Post

Header:

>Content type: application / JSON > authorization: key =... Your_ key …

Body:

{
  "registration_ids" :[devices_token],
  "priority" : "high",
  "notification" : {
    "body" : "Notification body here",
    "title" : "notification title here",
    "click_action": "action.open.facebook.with.url"
  },
  "data" : {
    "openURL" : "https://facebook.com/xxx"
  }
}

2) Android apps:

AndroidManifest.xml:

<activity android:name=".activity.OpenFacebookLink">
    <intent-filter>
        <action android:name="action.open.facebook.with.url" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

In subclasses of firebasemessagingservice:

@Override
public void onMessageReceived(RemoteMessage message) {
    super.onMessageReceived(message);
    String url = message.getData().get("openURL");
    if(message.getNotification()!=null) {
        // do some thing with url when app in foreground
    } else {
        // do some thing with url when app in background
    }
}

In your openfacebook link activity, do the following:

Intent intent = getIntent();
String url = intent.getStringExtra("openURL");
// do open facebook with url

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>