[英]Android 4.2.1 / 4.2.2 Notifications vibrate in silent mode
Prior to Android 4.2.1 the following code worked just fine 在Android 4.2.1之前,以下代码可以正常工作
notification.audioStreamType = AudioManager.STREAM_RING;
notification.flags = notification.flags | Notification.FLAG_INSISTENT
| Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(ID_NOTIFICATION_SOUND, notification);
Vibration is done separately, depending on the state of a preference setting. 根据首选项设置的状态,分别进行振动。
vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(vibr_pattern1, 0);
Now with Android 4.2.1+ there is always vibration even if the phone is set to silent (no vibration) and set to vibrate mode, even if the app settings for vibration are set to off. 现在,使用Android 4.2.1+,即使将手机设置为静音(无振动)并设置为振动模式,即使将振动的应用程序设置设置为关闭,也始终会产生振动。 Interestingly there is no vibration when the phone is in normal mode. 有趣的是,手机在正常模式下不会振动。
As mentioned, everything worked fine before 4.2.1. 如前所述,在4.2.1之前一切正常。
Can someone help? 有人可以帮忙吗? What did google change here? Google在这里做了什么更改? Is it related to this bug report ? 与这个错误报告有关吗?
Regards, 问候,
Andreas 安德烈亚斯
I fixed it like this: 我这样修复:
//vibration workaround for android 4.2.1+
notification.vibrate = new long[]{0,0};
//end workaround
I manually add "no vibration" and if the user chooses vibration it's done with an Vibrator
object. 我手动添加“无振动”,如果用户选择振动,则使用“ Vibrator
对象完成。 If not, the code above keeps everything quiet. 如果没有,上面的代码将使所有内容保持安静。 As mentioned before, this was not necessary before 4.2.1+ 如前所述,在4.2.1+之前不需要
I know this is old. 我知道这很旧。 But for some one who is looking for answer. 但是对于某些正在寻找答案的人。 You can try this. 你可以试试看
AudioManager audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
v.vibrate(500);
} catch (Exception e) {
e.printStackTrace();
}
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
v.vibrate(500);
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.