0
下面是生成內聯通知的代碼,一切正常,但我不想顯示MessageReply.class。添加內嵌回覆操作
當前問題:當發送消息時出現白屏,因爲掛起的意圖被稱爲 。
需要的結果:沒有這樣的白屏工作像whatsapp內嵌 通知。
void buildNotification(String messageValue) {
Intent intent = new Intent(this, Test.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Consts.EXTRA_MESSAGE, messageValue);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(Consts.GCM_NOTIFICATION)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageValue))
.setContentText(messageValue)
.addAction(buildReplyFromNotification(extras));
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
private NotificationCompat.Action buildReplyFromNotification(Bundle data) {
String replyLabel = getResources().getString(R.string.reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
// Create the reply action and add the remote input.
return new NotificationCompat
.Action
.Builder(R.drawable.ic_send, getString(R.string.reply_label), buildReplyPendingIntent(data))
.addRemoteInput(remoteInput)
.build();
}
private PendingIntent buildReplyPendingIntent(Bundle messageValue) {
Intent intent = new Intent(this, MessageReply.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Consts.EXTRA_DIALOG_ID, messageValue.getString("dialog_id"));
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}