【问题标题】:Notification not working properly on android api 28通知在 android api 28 上无法正常工作
【发布时间】:2020-05-05 14:38:02
【问题描述】:

我真的需要你的帮助。目前,我正在我的应用程序中开发通知模块。我的问题是通知适用于奥利奥,但不适用于奥利奥和派。我正在使用 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});
        }

我的问题的细节是,当条件打开但没有声音、振动时,正在通过电话接收通知。在锁屏状态下,通知不显示,没有指示灯,没有振动,没有声音。

有谁知道如何解决这个问题?谢谢大家,非常感谢您的帮助

【问题讨论】:

  • 请推送整个代码以设置通知(例如在哪里调用 mBuilder.build() 等)?
  • 我使用这个链接作为我的参考:stackoverflow.com/a/46991229/11851867
  • 你能在小米以外的其他安卓奥利奥设备上测试它吗?
  • 不幸的是我没有比小米其他的奥利奥设备。我想我会关闭这个问题并将您的答案标记为已接受,因为目前我决定实施您关于直接用户到通知设置的解决方案,同时我将继续试验并等待谷歌和其他开发人员的更新以优化所有 android 设备的通知开发从奥利奥开始。感谢您的解决方案,我真的很感激。
  • 也试试this之类的小技巧,看看能不能解决你的小米通知问题?

标签: android push-notification


【解决方案1】:

简短回答:使用另一个频道 ID 并查看它是否正常工作。

更多解释: android 通知通道的设置在创建后无法更改(但用户可以从应用通知设置中更改)。 因此,如果您想在创建频道后使用新设置,您有以下三种选择:

  1. 使用另一个频道 ID

  2. 删除旧频道并使用旧频道 ID 创建一个新频道,如 here 所述。

  3. 向用户发送通知设置以更改设置,如here 所述。

【讨论】:

  • 好的,我先试试,尽快通知结果
  • 我已经尝试使用另一个频道 ID,卸载并重新安装应用程序。但是问题还没有解决,有没有其他的解决方案,我可以不要求用户手动设置设置?
  • 已修改:我一直在尝试使用另一个频道 ID,卸载并重新安装应用程序。但是问题还没有解决,有没有其他的解决方案,我可以不要求用户手动设置设置?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-19
  • 2019-11-03
相关资源
最近更新 更多