Невозможно отправить уведомление Android с помощью диспетчера уведомлений.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Невозможно отправить уведомление Android с помощью диспетчера уведомлений.

Сообщение Anonymous »

Я пытаюсь отправить уведомление с помощью класса Notification Builder, но получаю сообщение об ошибке: Канал не найден.
Вот мой код:
Intent intent = new Intent(MainActivity.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, PendingIntent.FLAG_IMMUTABLE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this, "1")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Title")
.setContentText("content")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_DEFAULT;
String description = "description";
CharSequence name = getString(R.string.channel_name);
NotificationChannel channel = new NotificationChannel("1", name, importance);
channel.setDescription(description);
}

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(1, builder.build());

Ошибка Logcat:
1239-3921 NotificationService system_server E No Channel found for pkg=com.example.myapplication, channelId=1, id=1, tag=null, opPkg=com.example.myapplication, callingUid=10263, userId=0, incomingUserId=0, notificationUid=10263, notification=Notification(channel=1 shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
1239-1396 NotificationService system_server E No Channel found for pkg=com.example.myapplication, channelId=1, id=1, tag=null, opPkg=com.example.myapplication, callingUid=10263, userId=0, incomingUserId=0,


Подробнее здесь: https://stackoverflow.com/questions/791 ... on-manager
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»