静音后 - 无法取消静音

时间:2017-07-07 21:12:55

标签: android mute

静音是有效的,但是当我尝试取消静音时,它无法正常工作,我花了很多时间独自思考它,但没有运气。以下是我使用的方法:

public void MuteAudio(Context context){
    AudioManager mAlramMAnager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
    } else {
        mAlramMAnager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_ALARM, true);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_MUSIC, true);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_RING, true);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    }
}

public void UnMuteAudio(Context context){
    AudioManager mAlramMAnager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_UNMUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE,0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
        mAlramMAnager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_UNMUTE, 0);
    } else {
        mAlramMAnager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_ALARM, false);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_MUSIC, false);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_RING, false);
        mAlramMAnager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
    }
}

0 个答案:

没有答案