Android通知渠道默认始终为静音
创始人
2024-08-21 19:00:44
0

如果您想要在创建通知渠道时,默认情况下发送声音或震动通知,请将以下代码添加到通知渠道构建器中:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    AudioAttributes attributes = new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
            .build();

    NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription(channelDescription);
    channel.enableLights(true);
    channel.setLightColor(Color.RED);
    channel.enableVibration(true);
    channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), attributes);

    mNotificationManager.createNotificationChannel(channel);
} else {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(notificationTitle)
            .setContentText(notificationBody)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    mNotificationManager.notify(notificationId, builder.build());
}

这将允许您使用默认的通知设置,并在 Android SDK 版本号为O或更高版本时启用声音和震动通知。

相关内容

热门资讯

透视模拟器!aapoker透视... 透视模拟器!aapoker透视脚本下载(透视)透视脚本(切实存在有挂)进入游戏-大厅左侧-新手福利-...
透视工具!aapoker辅助软... 透视工具!aapoker辅助软件合法吗(透视)透视脚本入口(总是有挂)1、打开软件启动之后找到中间准...
透视好友房!aapoker怎么... 透视好友房!aapoker怎么提高中牌率(透视)透视插件(本来是真的有挂)1、下载好aapoker怎...
透视代打!aa poker透视... 透视代打!aa poker透视软件(透视)透视脚本(其实真的是有挂)1、操作简单,无需注册,只需要使...
透视辅助!aapoker真的假... 透视辅助!aapoker真的假的(透视)辅助插件工具(竟然真的有挂);1)aapoker真的假的辅助...
透视私人局!aapoker透视... 透视私人局!aapoker透视怎么用(透视)脚本(确实存在有挂)1、打开软件启动之后找到中间准星的标...
透视安装!aa poker透视... 透视安装!aa poker透视软件(透视)透视脚本(原来是真的有挂)1、下载好aa poker透视软...
透视肯定!aapoker怎么控... 透视肯定!aapoker怎么控制牌(透视)透视脚本入口(原来是真的有挂)aapoker怎么控制牌软件...
透视系统!aapoker如何设... 透视系统!aapoker如何设置胜率(透视)透视脚本下载(果然有挂);1、玩家可以在aapoker如...
透视好友!aapoker辅助插... 透视好友!aapoker辅助插件工具(透视)脚本(果然有挂)小薇(透视辅助)致您一封信;亲爱aapo...