Android Firebase推送通知无需单击即可打开活动
我对firebase推送通知有问题。 它不会自动打开通知,而是自动打开我放置的活动。我想要此行为,但在单击通知后 这是我的代码:Android Firebase推送通知无需单击即可打开活动,android,firebase,push-notification,android-pendingintent,Android,Firebase,Push Notification,Android Pendingintent,我对firebase推送通知有问题。 它不会自动打开通知,而是自动打开我放置的活动。我想要此行为,但在单击通知后 这是我的代码: @Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); final String title = remoteMessage.getData().get("title"); fi
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
final String title = remoteMessage.getData().get("title");
final String message = remoteMessage.getData().get("body");
showNotifications(title, message);
}
private void showNotifications(String title, String msg) {
Intent i = new Intent(this, OrderDetailActivity.class);
i.putExtra("order_id", 99);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Notification notification = new NotificationCompat.Builder(this)
.setContentText(msg)
.setContentTitle(title)
.setContentIntent(pendingIntent)
.setSmallIcon(R.mipmap.ic_launcher_logo)
.build();
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, notification);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
快速看一眼,我想知道你为什么需要悬挂式帐篷;?从以下文件: 执行与此挂起事件相关的操作 这就是为什么它可能会执行附加的意图。试着去掉那条线。更多信息,请参阅