当我第一次调试我的应用程序时,我会收到带有通知应用程序图标的推送通知,当我点击通知时,它会在我的Facebook页面上重定向到我。但在第二次推送通知中,没有获得通知应用程序图标以及未重定向到我的Facebook页面。
这是我通过邮递员发送的内容
{
"to":
"/topics/news",
"data": {
"extra_information": "This is some extra information"
},
"notification": {
"title": "NEW NOTIFICATION!",
"text": "Click me to open an Activity!",
"click_action": "DEARACTIVITY"
}
}
这是我的应用程序sendNotification方法
private void sendNotification(String title,String messageBody, String click_action) {
Intent intent;
if(click_action.equals("DEARACTIVITY")){
String url = "https://www.facebook.com/awwalsoft";
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
else if(click_action.equals("MAINACTIVITY")){
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else{
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
我想,每当我发送click_action = DearActivity,然后将推送通知重定向到我的Facebook页面。
答案 0 :(得分:0)
所以尝试这样做:
{
"to":
"/topics/news",
"data": {
"extra_information": "This is some extra information"
"title": "NEW NOTIFICATION!",
"text": "Click me to open an Activity!",
"click_action": "DEARACTIVITY"
}
}
要获取数据,请在FirebaseMessagingService中执行此操作:
String title=remoteMessage.getData().get("title");
String text=remoteMessage.getData().get("text");
String clickAction=remoteMessage.getData().get("click_action");
String extrainfo=remoteMessage.getData().get("extra_information");
并将字符串发送到通知。
最后:
if(clickAction.equals("DEARACTIVITY")){
String url = "https://www.facebook.com/awwalsoft";
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
else if(clickAction.equals("MAINACTIVITY")){
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else{
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}