环境:
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());
问题: