且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

禁用振动的通知

更新时间:2022-01-02 23:00:19

一个长期的试验和功放后,错误会议,我想我终于明白了什么是错的。

After a long trial & error session, I think I finally understood what's wrong.

问题就出在这个指令 notificationBuilder.setDefaults(Notification.DEFAULT_ALL)

无论你通过什么样的参数设置后, notificationBuilder.setVibrate() DEFAULT_ALL DEFAULT_VIBRATE 将被丢弃。有人在谷歌必须决定给予较高的precedence到使用setdefaults setVibrate

No matter what parameter you pass to notificationBuilder.setVibrate() after setting DEFAULT_ALL or DEFAULT_VIBRATE will be silently discarded. Someone at Google must have decided to give a higher precedence to setDefaults than to setVibrate.

这就是我结束了禁用的振动在我的应用程序的通知:

This is how I ended up disabling vibration for notifications in my app:

notificationBuilder.setDefaults(Notification.DEFAULT_LIGHT | Notification.DEFAULT_SOUND)
                   .setVibrate(new long[]{0l}); // Passing null here silently fails

这个作品,但感觉不对初始化一个新的长[] 只是为了禁止震动。

This works but doesn't feel right to initialize a new long[] just to disable the vibration.