无法在频道设置中启用音频

时间:2019-07-07 19:43:47

标签: android push-notification android-notifications notification-channel

我正在使用通知渠道,并且作为标准,我想启用通知声音。我在NotificationChannel选项中设置了声音,但已禁用。我还尝试在NotificationCompat.Builder中设置“音频”,但这都不起作用。

Ps:我不知道我的手机是否有问题,我有配备Android 9和MIUI的Redmi Note 7。

我已经尝试了Channel选项NotificationCompat.Builder,两者都单独使用,但是没有用。但是,如果我在“频道”设置中启用该选项,则可以使用,但我不希望用户这样做。

    String CHANNEL_ID = "coin_master_item_generator";
    CharSequence CHANNEL_NAME = "Item Generator Coin Master";

    AudioAttributes audioAttributes = new AudioAttributes.Builder()
    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
    .build();


    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
    channel.setDescription("Notifies when Items are generated");
    channel.enableVibration(true);
    channel.setVibrationPattern(new long[]{2000,1000});
    channel.enableLights(true);
    channel.setLightColor(Color.WHITE);
    channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),audioAttributes);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(channel);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_launcher_foreground)
        .setContentTitle("Item Generator")
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
        .setContentText("New Items generated");

    notificationManager.notify(1524,builder.build());

0 个答案:

没有答案