即使未设置声音,Android Oreo通知仍会发出声音.在旧版本上,完美运行 [英] Android Oreo notification keep making Sound even if I do not set sound. On Older version, works perfectly

查看:97
本文介绍了即使未设置声音,Android Oreo通知仍会发出声音.在旧版本上,完美运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使我的应用程序与Oreo兼容,并且面临通知方面的问题.

So I am making my app compatible with Oreo and facing issue with notification.

我根据文档添加了通知渠道,除通知在每次发布时保持声音正常外,其他所有操作均正常进行,并尝试将默认设置也设置为0.

I added notification channel according to documentation and everything is working smooth except notification keep making sound on every posting, tried setting defaults to 0 as well.

我正在模拟器中测试我的应用,非常感谢您的帮助.

I am testing my app in emulator, any help is highly appreciated.

使用此代码创建频道

  NotificationCompat.Builder builder = new NotificationCompat.Builder(PlayerService.this, "channel_01")
                            .setAutoCancel(false)
                            .setContentIntent(pendingIntent)
                            .setContent(viewsSmall)
                            .setCustomBigContentView(viewsExpanded)
                            .setDeleteIntent(pSwipeToDismiss);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder.setVisibility(Notification.VISIBILITY_PUBLIC);
            }

            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                builder.setPriority(Notification.PRIORITY_MAX);
            }


            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                            /* Create or update. */
                NotificationChannel channel = new NotificationChannel("channel_01",
                            "Playback Notification",
                            NotificationManager.IMPORTANCE_DEFAULT);
                    mNotificationManager.createNotificationChannel(channel);
                    mBuilder.setChannelId("channel_01");
                }
    final Notification notification = builder.build();

                    startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE,notification);

推荐答案

看看通知渠道设置(轻扫您的通知并按下面的设置图标,然后选择您的渠道).这些设置是在您首次创建频道时设置的,除非您在设备中手动进行设置,否则就不会进行修改(至少这是我从卸载和重新安装我的应用程序以了解默认情况下获得的设置的经验).

Take a look at the notification channel settings (swipe your notification and press the settings icon under it and then select your channel). Those settings are set the first time you create the channel and then not modified unless you do it manually in the device (at least that is my experience from uninstalling and reinstalling my app to see what settings I get by default).

基本上,channel.setSound(null, null) 仅在全新安装上创建频道时才有效.这可能就是他们试图在官方指南:

Basically, channel.setSound(null, null) will only have effect when you create the channel on a fresh installation. That might be what they try to explain in the official guide:

尝试使用其原始值创建现有的通知渠道不会执行任何操作

Attempting to create an existing notification channel with its original values performs no operation

如果您尝试遵循该指南并设置NotificationManager.IMPORTANCE_HIGH并且不使用channel.setSound(null, null),则该频道将获得具有默认声音的重要性级别Urgent Make sound and pop on screen.

If you tried to follow that guide and set NotificationManager.IMPORTANCE_HIGH and didn't use channel.setSound(null, null), the channel would get importance level Urgent Make sound and pop on screen with the default sound.

这篇关于即使未设置声音,Android Oreo通知仍会发出声音.在旧版本上,完美运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆