处理来自Firebase Android的通知
我试图了解Firebase。我成功地收到了它的通知。但是,当我点击通知时,如何打开另一个活动 这是我的代码:处理来自Firebase Android的通知,android,firebase,android-notifications,firebase-cloud-messaging,firebase-notifications,Android,Firebase,Android Notifications,Firebase Cloud Messaging,Firebase Notifications,我试图了解Firebase。我成功地收到了它的通知。但是,当我点击通知时,如何打开另一个活动 这是我的代码: public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = "MyFirebaseMsgService"; @Override public void onMessageReceived(RemoteMessage remote
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("test")
.setContentText(remoteMessage.getData().get("message"));
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
这是关于通知的事,与firebase无关
您需要定义通知的操作它是关于通知的,与firebase无关
您需要定义通知的操作您需要使用NotificationManager构建挂起的内容和通知
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.your_icon)
.setContentTitle("Notification Title")
.setContentText(messageBody)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
正如托森所建议的,如果您正在从Firebase控制台发送推送通知,您需要将有效负载放入
数据键,您需要构建一个挂起的内容并使用NotificationManager进行通知
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.your_icon)
.setContentTitle("Notification Title")
.setContentText(messageBody)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
正如托森所建议的,如果您正在从Firebase控制台发送推送通知,您需要将有效负载放入数据键是否正在从Firebase控制台发送通知?您需要使用数据消息可能重复的,如您所愿,我在这里找到解决方案您是否从Firebase控制台发送通知?您需要使用数据消息可能重复的,我在这里找到解决方案