Среда:
compileSdkVersion 26
buildToolsVersion "28.0.0"
compile 'com.google.android.gms:play-services-ads:11.4.0'
compile 'com.google.android.gms:play-services-gcm:11.4.0'
compile 'com.google.firebase:firebase-messaging:11.4.0'
** Описание: **
Я отправляю уведомление FCM из пакетной программы, и все работало нормально до версии 7.0.Теперь я изменил код для Android Oreo (использованные каналы и т. Д.) И вот результаты теста:
До версии 7.0:
Notification received when App is open? Yes
Notification received when App is in the background? Yes
Notification received when App is Closed? Yes
Версия 8.1 (Oreo):
Notification received when App is open? Yes
Notification received when App is in background? Yes
**Notification received when App is Closed? No**
Код
String channelId = "abc";
AudioAttributes audioAttr = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
NotificationChannel channel = new NotificationChannel(channelId, "abc", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("description");
channel.enableLights(true);
channel.setShowBadge(true);
channel.enableVibration(true);
channel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.s), audioAttr);
notificationManager.createNotificationChannel(channel);
Notification.Builder mBuilder = new Notification.Builder(getApplicationContext(), channelId)
.setSmallIcon(R.drawable.bell)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.cc))
.setContentTitle(title)
.setContentText(content)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setOngoing(true);
int notificationId = 1;
notificationManager.notify(notificationId, mBuilder.build());
Вопрос:
- Почему я не получаю уведомления, когда приложение закрыто?
- Почему значок уведомления не отображается?