我正在使用通知应用程序Firebase Cloud Messaging(FCM),并且我想在TextView
中填充我在新活动中收到的通知,当我单击通知时,该活动是显示,但没有通知消息
任何帮助请
这是我的代码
private void enviarNotificacion(RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
String title = data.get("title");
String body = data.get("body");
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "Acc";
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("title", title);
intent.putExtra("body", body);
PendingIntent pendingIntent = endingIntent.getActivity(this,0,intent,0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
builder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_notification)
.setTicker("Acc ")
.setContentTitle(title)
.setContentText(body)
.setVibrate(new long[]{0, 1000, 500, 1000})
.setContentIntent(pendingIntent)
.setContentInfo("info");
manager.notify(1, builder.build());
}
和我要在其中填充通知的main _
txtTitulo=(TextView) findViewById(R.id.titulotxt);
txtNotificacion=(TextView) findViewById(R.id.txtNotificacion);
Intent bundle= getIntent();
if (bundle != null) {
Titulo = bundle.getStringExtra("title");
MensajeNotificacion = bundle.getStringExtra("body");
txtTitulo.setText(Titulo);
txtNotificacion.setText(MensajeNotificacion);
}
答案 0 :(得分:1)
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("title", title);
intent.putExtra("body", body);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
尝试此操作来确定您的意图/待定意图