Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何关闭通知的默认振动_Android_Notifications_Vibration - Fatal编程技术网

Android 如何关闭通知的默认振动

Android 如何关闭通知的默认振动,android,notifications,vibration,Android,Notifications,Vibration,我正在使用Android 4.0的Galaxy Nexus,我在设置中将静音模式设置为振动。我使用NotificationManager.notify发送通知。我没有设置Notification.vibrate,我甚至使用myNotification.defaults&=~Notification.DEFAULT\u vibrate来禁用振动。但在调用NotifcationManager.notify后,它仍然会振动。 有人能告诉我如何在振动模式下关闭通知振动吗?使用以下代码: notifica

我正在使用Android 4.0的Galaxy Nexus,我在设置中将静音模式设置为振动。我使用NotificationManager.notify发送通知。我没有设置Notification.vibrate,我甚至使用myNotification.defaults&=~Notification.DEFAULT\u vibrate来禁用振动。但在调用NotifcationManager.notify后,它仍然会振动。
有人能告诉我如何在振动模式下关闭通知振动吗?

使用以下代码:

notification.defaults = Notification.DEFAULT_LIGHTS;
//or 
notification.defaults = Notification.DEFAULT_SOUND;

要动态管理通知设置,请执行以下操作:

notification.defaults = Notification.DEFAULT_LIGHTS;

if(/*sound enabled*/)
    notification.defaults |= Notification.DEFAULT_SOUND;

if(/*vibration enabled*/)
    notification.defaults |= Notification.DEFAULT_VIBRATE;

首先将振动设置按钮的值存储在共享首选项中。然后将此代码放置在收到通知的位置

SharedPreferences preferences = context.getSharedPreferences("VIBRATE",
            0);
boolean vibrate = preferences.getBoolean("vibrate", true);
if (vibrate) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }

为了在收到通知时禁用振动,我使用以下代码

notification.vibrate = new long[] { -1 };

而且它工作得很好。

对于特定的软件包,也可以使用以下adb命令来完成

adb shell
cmd appops set package_name VIBRATE ignore
上述命令将禁用包装的所有振动