Oreo-在应用关闭时未收到通知,但在后台运行正常

时间:2018-06-24 15:51:54

标签: android firebase-cloud-messaging android-8.0-oreo

环境:

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()); 

问题:

  1. 为什么我在关闭应用程序后没有收到通知?
  2. 为什么通知徽章不显示?

0 个答案:

没有答案