如何仅静音我的应用程序

时间:2017-07-22 18:19:32

标签: java android audio

我需要将我的应用静音(关闭)。当我使用AudioManager时,它会将所有系统静音(关闭)。我的应用程序没有任何音频文件只是android的标准声音。 有任何建议吗?

public class Main_Activity extends Activity {
private ImageButton btn_soundSwitcher = null;
boolean sound = false;
AudioManager audioManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

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


    btn_soundSwitcher = (ImageButton) findViewById(R.id.iImgBtn_sound_switch);

    View.OnClickListener onClickListener = v -> {
        switch (v.getId()) {
                case R.id.iBtn_start_game:
                startActivity(new Intent(v.getContext(), Game_Activity.class));
                break;
            case R.id.iImgBtn_info_about_game:
                startActivity(new Intent(v.getContext(), Info_app_Activity.class));
                break;
            case R.id.iImgBtn_sound_switch:
                if(sound){
                    temp.setText("Turn OFF");

                    audioManager.setMode(AudioManager.MODE_IN_CALL);
                    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);

                    btn_soundSwitcher.setImageResource(R.drawable.sound_switcher_btn_off);
                    sound = false;
                }else {
                    temp.setText("Turn ON");

                    audioManager.setMode(AudioManager.MODE_NORMAL );
                    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);

                    btn_soundSwitcher.setImageResource(R.drawable.sound_switcher_btn_on);
                    sound = true;
                }
                break;
        }
    };
}

}

0 个答案:

没有答案