Я не хочу показывать уведомление, когда приложение запущено или открыто.Я использую службу диспетчера сигнализации для создания уведомлений я Android Studio.я получаю уведомление, когда приложение открыто.так что я хочу остановить это.и хотите уведомление только тогда, когда приложение является фоновым или убитым.
private void notificationDialog() {
NotificationManager notificationManager = (NotificationManager) context1.getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "tutorialspoint_01";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_LOW);
// Configure the notification channel.
notificationChannel.setDescription("New Message Received");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context1, NOTIFICATION_CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setVibrate(null)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setTicker("Tutorialspoint")
//.setPriority(Notification.PRIORITY_MAX)
.setContentTitle("New Message Received")
.setContentText("This is sample notification")
.setContentInfo("Information");
notificationManager.notify((int)System.currentTimeMillis(), notificationBuilder.build());
}