Java Android:通知不会生成默认声音

Java Android:通知不会生成默认声音,java,android,firebase,firebase-cloud-messaging,android-notifications,Java,Android,Firebase,Firebase Cloud Messaging,Android Notifications,我正在尝试使用声音生成FCM通知。我收到通知等没有问题,但没有任何声音。我同意默认的通知声音。请检查下面的代码。适用于API 26及以上 NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // The id of the channel. String id

我正在尝试使用声音生成FCM通知。我收到通知等没有问题,但没有任何声音。我同意默认的通知声音。请检查下面的代码。适用于API 26及以上

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

                // The id of the channel.
                String id = "xxx";

                // The user-visible name of the channel.
                CharSequence name = "xxx";

                // The user-visible description of the channel.
                String description = "xxx";

                int importance = NotificationManager.IMPORTANCE_DEFAULT;

                NotificationChannel mChannel = new NotificationChannel(id, name, importance);

                // Configure the notification channel.
                mChannel.setDescription(description);

                mChannel.enableLights(true);
                // Sets the notification light color for notifications posted to this
                // channel, if the device supports this feature.
                mChannel.setLightColor(Color.RED);

                mChannel.enableVibration(true);
                mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});


                mNotificationManager.createNotificationChannel(mChannel);

                mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);



                // The id of the channel.
                String CHANNEL_ID = "xxx";

                // Create a notification and set the notification channel.
                Notification notification = new Notification.Builder(this,"xxx")
                        .setSmallIcon(R.drawable.volusha_notifications)
                        .setContentText(text)
                        .setChannelId(CHANNEL_ID)
                        .setContentIntent(pendingIntent)
                        .setContentTitle(title)
                        .setAutoCancel(true)
                        .build();

                // Issue the notification.
                mNotificationManager.notify(new Random().nextInt(), notification);
为什么会发生这种情况,以及如何获得默认声音

更改此部分:

// Create a notification and set the notification channel.
                Notification notification = new Notification.Builder(this,"xxx")
                        .setSmallIcon(R.drawable.volusha_notifications)
                        .setContentText(text)
                        .setChannelId(CHANNEL_ID)
                        .setContentIntent(pendingIntent)
                        .setContentTitle(title)
                        .setAutoCancel(true)
                        .build();

尝试使用获取默认通知Uri,如下所示:

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);

在Notification.Builder(this,“”.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知))中您将获得声音或传递自定义通知声音的自定义声音URI您是否从控制台发送FCM通知?如何获得通知?尝试使用
NotificationManager。重要性\u HIGH
您也可以使用setDefaults(Notification.DEFAULT \u sound)@YohanWeerasinghe
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);