Я пытаюсь отправить уведомление с помощью класса 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
Невозможно отправить уведомление Android с помощью диспетчера уведомлений. ⇐ JAVA
Программисты JAVA общаются здесь
1730223025
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,
Подробнее здесь: [url]https://stackoverflow.com/questions/79128020/unable-to-send-android-notification-using-notification-manager[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия