I have a simple settings menu where I have a CheckBoxPreference
. I want to set silence mode when the checkBox is checked and normal mode when it is not checked. The sound code I already have, but I'm having trouble getting the value of checkBoxPreference, since I only have the settings class that extends PreferenceActivity
. Here is the code below:
Prefs.java
package br.com.pedro.menu;
import br.com.pedro.school.R;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Prefs extends PreferenceActivity {
AudioManager som;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
// USE AudioManager for Settingringing from vibration
som = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
}
}
xml / prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/geral" >
<CheckBoxPreference
android:key="silenciar"
android:summary="@string/mudo_inst"
android:title="@string/mudo" />
</PreferenceCategory>
Please help me!