简体   繁体   English

Android 4.2.1 / 4.2.2通知以静音模式振动

[英]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.

相关问题 Android ICS控制静音模式关闭,振动或静音 - Android ICS control Silent Mode Off, Vibrate, or Mute Android:如何在振动设置之间切换(始终、从不、仅在静音模式下、仅在不处于静音模式时)? 重访 - Android: How to Toggle Between Vibrate Settings (Always, Never, Only in Silent Mode, Only When Not in Silent Mode)? Revisited Android BroadCast接收器,用于振动和静音 - Android BroadCast receiver for vibrate and silent 如何在后台更改铃声模式(振动或静音) - how to change ringer mode in background(Vibrate or Silent) 如何在 react-native android 应用程序中将铃声模式更改为静音/响铃/振动? - How to change ringer mode to Silent/Ring/Vibrate on click in react-native android application? 虽然设置了手机静音模式,但在Android通知中播放声音 - Play sound in Android notifications although phone silent mode is set 使 android 通知静音且仅振动 - Make android notification silent and only vibrate Android通知和服务振动 - Android notifications and vibrate from service Android静默推送通知 - Android silent push notifications Android上的静音通知 - Silent notifications on Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM