Подскажите пожалуйста как создать Notification без всплывающего окна. Например как в google mail - при поступлении письма появляется иконка приложения в верху экрана, но нет всплывающего окна.
Мой код
@RequiresApi(api = Build.VERSION_CODES.O)
private void startMyOwnForeground(final String title, final int ico){
String NOTIFICATION_CHANNEL_ID = "xxx.xxxxxxxx.xxxx.com";
String channelName = "iknow";
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_MIN);
chan.setSound(null, null);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);
notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.setOngoing(true)
.setContentIntent(getPendingIntent())
.setSmallIcon(ico)
.setContentTitle(title)
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_EMAIL)
.build();
startForeground(2, notification);
}
Как раз недавно была противоположная задача, нужно было показывать heads-up уведомления, а они никак не хотели показываться. В итоге, после того, как я указал id канала setChannelId(channelId), уведомления стали показываться в режиме heads-up. Так что в теории, без id, с низким приоритетом, уведомления будут отображатсья только в статус-баре.
Попробуй такой вариант:
Intent intent = new Intent(this, BaseActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, "blah_blah")
.setContentTitle(messageAuthor)
.setContentText(messageBody)
.setSmallIcon(R.drawable.ic_notification_small)
.setLargeIcon(R.drawable.ic_notification_large))
.setContentIntent(pendingIntent)
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, notificationBuilder.build());
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости