我可以重置音量吗?

时间:2015-11-06 04:41:32

标签: java android service manifest volume

我使用以下代码静音我的应用程序:

    private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        if (e.NewSize.Width > e.NewSize.Height)
            this.myPanel.Template = this.Resources["Scientific"] as ControlTemplate;
        else
            this.myPanel.Template = this.Resources["Standard"] as ControlTemplate;
    }

问题是,我希望能够取消静音应用到与用户最初相同的音量。现在,我只能控制音量将用户重置为:

          AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);


        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
        Toast.makeText(Main_Menu.this, "MUTED", Toast.LENGTH_SHORT).show();

我看到某个地方在开始时获取音量,然后稍后使用该值重置。这对我来说不起作用,因为用户不断切换回活动,我不能一次性变量重置。

有没有什么方法可以将用户音量重置为通过我的应用程序更改之前的用户数量?

谢谢,

   AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 4, 4);
        Toast.makeText(Main_Menu.this, "UNMUTED", Toast.LENGTH_SHORT).show();

1 个答案:

答案 0 :(得分:0)

    AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);


    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    Toast.makeText(Main_Menu.this, "MUTED", Toast.LENGTH_SHORT).show();

您已经完成了所需的操作,只需在上面的代码中进行以下修改即可。

    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,userVolume, 0);
    Toast.makeText(Main_Menu.this, "MUTED", Toast.LENGTH_SHORT).show(); //user volume you will get by getStreamVolume()