Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何禁用/重新启用接收到通知时发生的振动?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当收到通知时,我正在为特定功能定义自定义振动.

但是,当手机屏幕关闭时,自定义振动与@L_616_5@认通知振动一起播放.

我试图将手机置于静音模式,并以编程方式将其从静音模式中删除,并尝试使用部分唤醒锁,怀疑当cpu处于关闭状态时,也会抛出@L_616_5@认振动,但这两种方法似乎都不起作用.

我也尝试将@L_616_5@认音频和振动静音,并在完成任务后恢复通知,但这只能帮助屏蔽@L_616_5@认通知声音,而不是@L_616_5@认的振动.

//Trying to mute the notification sound and vibration
au@L_553_18@manager.setStreamVolume(Au@L_553_18@manager.STREAM_NOTIFICATION,Au@L_553_18@manager.FLAG_REMOVE_SOUND_AND_VIBRATE);
 //Restoring the defaults
au@L_553_18@manager.setStreamVolume(Au@L_553_18@manager.STREAM_NOTIFICATION,defaultNotifVolume,Au@L_553_18@manager.FLAG_REMOVE_SOUND_AND_VIBRATE);

请让我知道如何以编程方式禁用/启用@L_616_5@认通知振动.

解决方法

尝试这样做
NotificationCompat.builder notificationBuilder = (NotificationCompat.builder) new NotificationCompat.builder(this);

这将导致振动的模式
使用通知生成器并删除设置的振动,这将禁用振动

这是我处理声音和震动的例子
例如:

Uri soundUri = @L_575_30@manager.getDefaultUri(@L_575_30@manager.TYPE_NOTIFICATION);
        NotificationCompat.builder notificationBuilder = (NotificationCompat.builder) new NotificationCompat.builder(this)
                .setsmallIcon(R.mipmap.ic_launcher)
                .setContentText(body)
                .setContenttitle(titlE)
                .setSound(soundUri)
                .setLargeIcon(icon)
                .setSound(soundUri)
                .setLights(Color.parseColor("#ffb400"),50,10)
                .setVibrate(new long[]{500,500,500})
                .setAutoCancel(true)
                .setContenTintent(pendingIntent);

        notificationmanager notificationmanager = (notificationmanager) getSystemservice(Context.NOTIFICATION_serviCE);
        notificationmanager.notify(0,notificationBuilder.build());

大佬总结

以上是大佬教程为你收集整理的android – 如何禁用/重新启用接收到通知时发生的振动?全部内容,希望文章能够帮你解决android – 如何禁用/重新启用接收到通知时发生的振动?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。