通知在android api 28上无法正常工作

通知在android api 28上无法正常工作,android,push-notification,Android,Push Notification,我真的需要你的帮助。目前,我正在我的应用程序中开发通知模块。我的问题是,通知在奥利奥下有效,但在奥利奥和馅饼上不起作用。我正在使用mi(小米)设备,下面是我的代码: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = notificationManager.getNotificationChannel(CHANNEL_ID); if (chan

我真的需要你的帮助。目前,我正在我的应用程序中开发通知模块。我的问题是,通知在奥利奥下有效,但在奥利奥和馅饼上不起作用。我正在使用mi(小米)设备,下面是我的代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = notificationManager.getNotificationChannel(CHANNEL_ID);
        if (channel == null){
            channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
                channel.enableLights(true);
                channel.enableVibration(true);
                channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
                AudioAttributes att = new AudioAttributes.Builder()
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .build();
                channel.setSound(Uri.parse(sound), att);
                notificationManager.createNotificationChannel(channel);
            }
            mBuilder = new NotificationCompat.Builder(mContext, CHANNEL_ID);
            mBuilder.setSmallIcon(icon)
                    .setTicker(message)
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(true)
                    .setContentTitle(title)
                    .setContentIntent(resultPendingIntent)
                    .setSound(Uri.parse(sound))
                    .setLights(0xff00ff00, 500, 500)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(notificationVO.getMessage()))
                    .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
                    .setContentText(message)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        }
我的问题的细节是,当条件打开时,通过电话接收通知,但没有声音、振动。在锁屏中,通知未显示、无led、无振动和无声音


有人知道如何解决这个问题吗?谢谢大家,我非常感谢你们的帮助。

简短回答:使用另一个频道id,看看它是否正常工作

更多说明:android通知频道的设置在创建后不能更改(但用户可以从应用程序通知设置中更改)。 因此,如果您希望在创建频道后为频道使用新设置,您有三种选择:

  • 使用另一个通道id

  • 如前所述,删除旧频道并使用旧频道id创建新频道

  • 如前所述,将用户发送到通知设置以更改设置


  • 好的,我会先试试,并尽快通知结果。我已经尝试了用户另一个频道id,卸载并重新安装该应用程序。但是问题仍然没有解决,有没有其他解决方案,我可以不要求用户手动设置设置吗?修订:我已经尝试使用另一个频道id,卸载并重新安装应用程序。但是这个问题还没有解决,有没有其他解决方案,我可以不要求用户手动设置设置?请推送整个代码来设置通知(比如调用mBuilder.build()等等)?我使用这个链接作为参考:你能在小米以外的其他android oreo设备上测试它吗?不幸的是,我没有小米以外的其他oreo设备。我想我会结束这个问题,并将你的答案标记为已接受,因为目前我决定实施你关于直接用户到通知设置的解决方案,同时我将继续实验并等待谷歌和其他开发人员的更新,以优化从oreo开始的所有android设备的通知开发。谢谢你的解决方案,我真的很感激。也尝试使用一些技巧,比如看看它是否能解决你的小米通知问题?