安卓ICS控制静音模式关闭,振动或静音 [英] Android ICS control Silent Mode Off, Vibrate, or Mute

查看:140
本文介绍了安卓ICS控制静音模式关闭,振动或静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处找我能想到的找到一个答案,而且也有关于Android的音频问题批次,但没有,我可以找到谈谈ICS新的设置。

I've looked everywhere I can think of to find an answer to this, and there are LOTS of questions about the audio in Android, but none that I can find that talk about the new settings in ICS.

我的应用程序有一个功能,用户可以preSS一个按钮,手机的铃声会沉默,以及无振动。这是我的code,它到现在为止已经过精:

My app has a feature where the users can press a button and the phone's ringer will be silent, along with no vibration. Here is my code, which up until now has worked fine:

        mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

现在发生的事情是,当用户presses按钮,音量变为0还在,但手机,特别是银河S3,有一个很短震动。然后在设置 - >声音,静音模式已经从关振动。因此,一旦某些事情发生,但它仍然有一个短的振动通知。我一直没能彻底测试足以知道具体是什么情况,以便它振动这样的,但是这不是问题的问题。

Now what happens is that when the user presses the button, the volume goes to 0 still, but the phone, specifically the Galaxy S3, has a short vibrate. Then in Settings->Sound, Silent Mode has been changed from Off to Vibrate. So whenever certain things happen, it still has that short vibrate notification. I haven't been able to test thoroughly enough to know what specifically happens in order for it to vibrate like that, but that's not the point of the question.

我的问题是,我们如何能够控制关,振动和静音的ICS静音模式设置?我希望能够将其设置为静音,当他们打的按钮,然后回去关,或任何他们不得不将其设置为,当他们再次击中它。我尝试使用mAudioManager.setStreamMute方法,但是这不是所期望的效果,并且它也不会改变的静音模式设定。

My question is how can we control the ICS Silent Mode settings of Off, Vibrate, and Mute? I want to be able to set it to Mute when they hit that button, and then go back to Off, or whatever they had it set to, when they hit it again. I tried using the mAudioManager.setStreamMute method, but this is not the desired effect, and it also doesn't change the setting of Silent Mode.

在此先感谢您的帮助,这是pciated !!多少AP $ P $

Thanks in advance for any help, it's much appreciated!!

推荐答案

确定我想通了!!!! +1 iturki您的帮助,谢谢!我曾试图RINGER_MODE_SILENT了,但没想到它的工作。它没有工作,但这是因为它是只有一半的解决方案。这是必要的,但!

OK I figured it out!!!! +1 to iturki for the help, thanks!! I had tried the RINGER_MODE_SILENT already, but didn't think it worked. It didn't work, but that's because it was only half the solution. It is needed though!

下面是它每次都为我工作的方式:

Here's the way it is working for me every time:

我发现,在任何设置AudioManager.RINGER_MODE_NORMAL或AudioManager.RINGER_MODE_SILENT,我仍然收到了通知的振动。这就是为什么我评论说,它没有工作。经过进一步的测试,我发现它是不是导致这个RINGER_MODE设置,它实际上是这一行的code:

I found that with either setting AudioManager.RINGER_MODE_NORMAL or AudioManager.RINGER_MODE_SILENT, I was still receiving the vibrations for notifications. This is why I commented that it didn't work. After further testing, I found that it is not the RINGER_MODE setting that is causing this, it is in fact this line of code:

mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

由于某种原因未知对我来说,与正常或静音或者RINGER_MODE设置,当STREAM_RING音量设置为0,以这种方式,它改变了静音模式在设置 - >声音设置为振动。

For some reason unknown to me, with either RINGER_MODE setting of NORMAL or SILENT, when the STREAM_RING volume is set to 0 in this way, it changes the Silent Mode setting in Settings->Sound to Vibrate.

解决办法:

    mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
    mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

我不得不删除STREAM_RING设置,只是息事宁人。现在,当我将它设置为RINGER_MODE_SILENT,独自离开STREAM_RING,没有更多的烦人半秒的震动!一个额外的说明,我没有测试过的VibrateSetting设置为OFF时,它仍然工作,但我要离开它在我的应用程序的其他原因。

I had to remove the STREAM_RING setting and just leave it alone. Now, when I set it to RINGER_MODE_SILENT and leave the STREAM_RING alone, no more annoying half second vibrations!!! One extra note, I tested without setting the VibrateSetting to OFF, and it still worked, but I'm leaving it for other reasons in my app.

重要提示:我不知道如何从RINGER_MODE_NORMAL此更改RINGER_MODE_SILENT会影响Android系统previous版本,所以要小心。如果有人确切地知道这是什么变化将在previous版本的影响,请随时让我们知道!

IMPORTANT: I don't know how this change from RINGER_MODE_NORMAL to RINGER_MODE_SILENT will affect previous versions of Android, so be careful. If anyone knows for sure what this change would affect on previous versions, please feel free to let us know!

再次感谢iturki您的帮助!

Thanks again iturki for the help!

这篇关于安卓ICS控制静音模式关闭,振动或静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆