android - Android,允许用户选择音频配置文件并将其保存以供以后使用

标签 android audio android-audiomanager

我看到的教程允许用户通过立即单击按钮来激活音频/声音配置文件,我不想立即激活选定的配置文件,我想保存用户对声音配置文件的选择并稍后针对某个事件激活该选择,如何我这样做,还建议一些好的资源来学习android中与音频相关的东西。我也想对铃声,消息和通知量进行相同的处理

最佳答案

您可以使用Android偏好设置保存用户的选择,以备后用:

//save prefs
public void savePrefs(String key, Boolean value){
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean(key, value);
    editor.commit();
}

//get prefs
private String loadPreferences(String key, Boolean value){
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String data = sharedPreferences.getBoolean(key, value);
    return data;
}

如果用户单击音频按钮,请在代码中将audioChoice = true设置。然后将audioChoice保存到首选项中:
private boolean audioChoice = false;

audioChoice = savePrefs("Choice", audioChoice);

如果要在以后检索audioChoice,请执行以下操作:
audioChoice = loadPreferences("Choice", audioChoice);

如果您需要更多信息,请参见以下有关使用SharedPreferences的android文档:
http://developer.android.com/guide/topics/data/data-storage.html#pref

关于android - Android,允许用户选择音频配置文件并将其保存以供以后使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31861951/

相关文章:

android - SoundPool 中的流音量与 AudioManager 中的音量

android - 在 Android 版本 4.2.2 中通话电话在 MODE_IN_CALL 中不起作用

flutter - 如何一个一个播放多个音频?

c# - 生成 WAV 文件铃声

android - UnsatisfiedLinkError 安卓

Android - ListView 中的单选按钮?

iphone - iOS xcode4 AVQueuePlayer 不播放声音

android - (Android) 将一个音频叠加到另一个音频

android - Leanback.DetailsFragment 未按预期滚动

java - 为什么我的 "if (p.exitValue() != 0)"代码运行两次?