Suppose in my notification,Today is X's birthday it opens FB link of X on clicking the notification and same for Y, How to do it using firebase
Below is the way to do that:
1) server site make request with:
Request URL: 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 app:
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 your subclass 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 OpenFacebookLink
activity let do that:
Intent intent = getIntent();
String url = intent.getStringExtra("openURL");
// do open facebook with url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With