我正在使用带有 Android 4.0 的 Galaxy Nexus,我在设置中将静音模式设置为振动。我使用 NotificationManager.notify 发送通知。我没有设置 Notification.vibrate,我什至使用 myNotification.defaults &= ~Notification.DEFAULT_VIBRATE 来禁用振动。但是在调用 NotifcationManager.notify 后它仍然会振动。谁能告诉我如何在振动模式下关闭通知的振动?
问问题
6631 次
5 回答
4
使用以下代码:
notification.defaults = Notification.DEFAULT_LIGHTS;
//or
notification.defaults = Notification.DEFAULT_SOUND;
于 2012-03-14T04:09:42.120 回答
1
动态管理通知设置:
notification.defaults = Notification.DEFAULT_LIGHTS;
if(/*sound enabled*/)
notification.defaults |= Notification.DEFAULT_SOUND;
if(/*vibration enabled*/)
notification.defaults |= Notification.DEFAULT_VIBRATE;
于 2012-08-20T14:26:43.607 回答
1
要在通知到来时禁用振动,我使用此代码。
notification.vibrate = new long[] { -1 };
而且它工作得很好。
于 2016-04-08T06:48:44.007 回答
0
首先将您的振动设置按钮的值存储在共享偏好中。然后将此代码放在收到您的通知的位置。
SharedPreferences preferences = context.getSharedPreferences("VIBRATE",
0);
boolean vibrate = preferences.getBoolean("vibrate", true);
if (vibrate) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
}
于 2013-09-25T05:49:00.050 回答
0
也可以使用以下针对特定包的 adb 命令来完成
adb shell
cmd appops set package_name VIBRATE ignore
上述命令将禁用 package_name 包的所有振动。
于 2020-04-27T19:13:36.970 回答