android - 关闭声音效果

标签 android audio options

嗨,我是android开发的新手,我正在尝试制作游戏。我目前想为我的游戏禁用声音效果,可以在首选项 Activity 中打开或关闭该效果。

public static  void initSounds(Context theContext)
    {

        if(OptionsMenu.getSounds(theContext))
        {
             mContext = theContext;
             mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
             mSoundPoolMap = new HashMap();
             mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        }
    } 

但是,当我这样做时,声音效果不会关闭。

最佳答案

如果您使用的是默认的SharedPreferences,则只需执行以下操作即可:

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    nixonMode=prefs.getBoolean("nixonmode", false);

关于android - 关闭声音效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726647/

相关文章:

java - @Before 注释在 espresso 测试中被 kotlin 忽略?

android - 无法通过 Android Studio 启动应用程序(logcat [DEAD])

带有类别的Android GridView?

javascript:发送带有音频文件的 POST,然后重定向到新页面

r - 如何在 R 中调整 future.global.maxSize?

android - 切换按钮事件不适用于各种设备

winforms - VideoLan.Net : Play media backwards/Change playback speed?

javascript - Webaudio,播放声音两次

c++ - GCC C++编译选项-mcpu

C - 检查主要参数