模拟器上没有通知声音

模拟器上没有通知声音

本文介绍了模拟器上没有通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Android 上的 notifications 问题感到很生气:在我开发项目时,突然间模拟器不再播放 API 26 及更高版本的通知声音,

I am going nuts with a problem with notifications on Android: While I was developing my project, suddenly the emulator plays no notification sounds anymore for API 26 and higher,

例如需要通道的 API.当然,我已经建立了一个频道,而且以前效果很好!我重新安装了应用程序,删除了频道,甚至用 API 27 设置了另一个 AVD,结果相同:没有声音!(通知确实弹出)

e.g. the API which require a channel.Of course I have set up a channel and it has worked great before! I have reinstalled the app, deleted the channel, even set up another AVD with a API 27, same result: no sound ! (the notification does pop up)

显然,我已经检查过是否启用了通知声音,对于这个特定频道,一切似乎都很好,只是没有声音.如果我使用以下方法进行测试:

Obviously I have checked that notification sounds are enabled, also for this specific channel, all seems OK, just no sounds.If I play a test using:

RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).play();

它可以正常工作,所以没有硬件问题.在不需要通道的较低 API 前 26 上,声音会播放.

it works as it should, so no hardware problem.On lower APIs pre 26 where you don't need a channel, the sound does play.

有人遇到过同样的问题吗?

Anybody had the same problem?

//make the channel
//The Config class is imported and the constants resolved, not the problem


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            NotificationChannel channel = new NotificationChannel(
                    Config.CHANNEL_1_ID,
                    Config.CHANNEL_1_NAME,
                    NotificationManager.IMPORTANCE_HIGH);

            channel.setDescription(Config.CHANNEL_1_DESC);
            channel.enableLights(true);
            channel.enableVibration(true);
            channel.setShowBadge(true);

          NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(channel);
}

// send notification
 NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context, Config.CHANNEL_1_ID)
                    .setSmallIcon(R.drawable.ic_notifications_black_24dp)
                        .setContentTitle(title)
                        .setContentText(body)
                        .setAutoCancel(false)
                        .setColor(context.getResources().getColor(R.color.colorPrimary))
                        .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
                        .setPriority(NotificationCompat.PRIORITY_HIGH);

        NotificationManagerCompat mNotificationMgr = NotificationManagerCompat.from(context);
        mNotificationMgr.notify(1, mBuilder.build());

推荐答案

似乎我找到了答案:我必须通过模拟器上的完成设置您的 Android SDK"向导.单击所有内容的跳过",现在它似乎又可以工作了.奇怪的是,我最初并没有这样做,但通知仍然按预期工作......呃!

Seems I found the answer: I had to go through the "Finish setting up your Android SDK" wizard on the emulator. Clicked "skip" for everything, now it seems to work again.Weirdly enough, I didn't do that initially and still the notifications worked as expected... duh !

这篇关于模拟器上没有通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:52