美文网首页
android通知 震动不生效问题

android通知 震动不生效问题

作者: 吉凶以情迁 | 来源:发表于2024-09-04 17:21 被阅读0次
  //Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        //  Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.custom_sound);
        Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context,RingtoneManager.TYPE_NOTIFICATION);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = createChannel(context, PUSH_CHANEL_ID, PUSH_CHANEL);//只需要创建一次。。
            // 设置通道的声音
            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .build();

            channel.setSound(soundUri, audioAttributes);
            channel.enableVibration(true);
            channel.canShowBadge();
            channel.enableLights(true);
            long[] vibrationPattern = {600, 100, 600, 100, 600, 100, 400, 100,100};
            channel.setVibrationPattern(vibrationPattern);
            notificationManager.createNotificationChannel(channel);
        }

修改成了其他铃声,发现不生效,我给他重启依然不生效,我试过卸载发现修改的铃声终于生效了,至于震动之前没震动,我卸载重装后 也生效了。

相关文章

网友评论

      本文标题:android通知 震动不生效问题

      本文链接:https://www.haomeiwen.com/subject/adxrljtx.html