У меня есть push-уведомления, поступающие в приложение.Однако в API 24 уведомление, которое я показываю, появляется только в строке состояния, но оно не отображается (как всплывающее окно) и не издает никаких звуков.
Я не могу понять, почему...
Вот мой код:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 1;
String channelId = "channel-03";
String channelName = "Channel Name";
int importance = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
Log.d(TAG, "android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N");
importance = NotificationManager.IMPORTANCE_HIGH;
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Log.d(TAG, "android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O");
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(icon)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
Intent intent1 = new Intent(context, MainActivity.class);
stackBuilder.addNextIntent(intent1);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
notificationManager.notify(notificationId, mBuilder.build());