Расширенное уведомление
У меня есть уведомление о том, что я хочу, чтобы его отображали сразу после его создания.
мой код прямо сейчас:
Intent myIntent = new Intent(WearRunActivity.this, ResultsActivity.class);
myIntent.putExtra("distance", distance);
myIntent.putExtra("time", chronometer.getText());
myIntent.putExtra("pace", pace);
myIntent.putExtra("speed", speedAc);
myIntent.putExtra("lSteps", leftSteps);
myIntent.putExtra("rSteps", rightSteps);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//WearRunActivity.this.startActivityIfNeeded(myIntent, 1);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.card_icon)
.setContentTitle("REPORT")
.setContentText(chronometer.getText())
.setLargeIcon(BitmapFactory.decodeResource(
getResources(), R.drawable.card_icon))
.setAutoCancel(true)
.setContentIntent(pendingIntent);
notification_manager = NotificationManagerCompat.from(this);
notification_manager.notify(1, notificationBuilder.build());
С помощью этого кода создается уведомление, но оно не отображается автоматически на экране. Мне нужно пролистать все ожидающие уведомления, чтобы найти его. Что я хочу, чтобы это уведомление отображалось на экране автоматически после его создания, какие-либо предложения?
1 ответ
Решение
Я нашел способ!
При создании уведомления добавьте строку .setOngoing(True), чтобы при отправке уведомления оно отображалось поверх всех ожидающих уведомлений и отображалось на экране.
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.card_icon)
.setContentTitle("Report")
.setContentText(chronometer.getText())
.setLargeIcon(BitmapFactory.decodeResource(
getResources(), R.drawable.card_background_blur))
.setAutoCancel(true)
.setOngoing(true)
.setContentIntent(pendingIntent);