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或更高版本时启用声音和震动通知。

相关内容

热门资讯

黑科技教学!(wEpoke)软... 黑科技教学!(wEpoke)软件透明挂,(wepOke)确实是有挂,AA德州教程(有挂技巧);大神普...
wepoke有挂吗蓝鸟!wep... wepoke有挂吗蓝鸟!wepoke系统规律,poker有没有外挂,2025新版技巧(最初是真的有挂...
黑科技辅助!(wopoker)... 1、黑科技辅助!(wopoker)软件透明挂,(WePoKer)好像真的有挂,扑克教程(有挂透明)。...
wepok软件透明挂!aa p... wepok软件透明挂!aa poker有没有挂,微扑克wpk有挂吗,黑科技教程(原生有挂);《WPK...
黑科技肯定!(wPK)透视辅助... 黑科技肯定!(wPK)透视辅助app,(wPk)切实是有挂,新2025教程(有挂技巧)是由北京得wP...
德扑ai智能工具!wopoke... 德扑ai智能工具!wopoker苹果怎么下载,wepoke真的有挂嘛,细节方法(固有真的有挂)1、很...
黑科技教学!(wEpOke)软... 黑科技教学!(wEpOke)软件透明挂,(wepoKE)从前有挂,插件教程(有挂教程);建议优先通过...
德州ai辅助软件排名!aapo... 此外,数据分析德州(aapoker安卓版辅助)辅助神器app还具备辅助透视行为开挂功能,通过对客户a...
黑科技安装!(aapokER)... 黑科技安装!(aapokER)透明挂辅助脚本,(aaPoker)起初是真的有挂,wpk教程(有挂透视...
aapoker有挂!wepok... aapoker有挂!wepoke外挂,微扑克ai技术,透明挂教程(先前真的是有挂);支持2-10人实...