首先建立/res/xml/settings.xml
android:defaultValue="true"
android:key="@string/cbp_push_notification"
android:summaryOff="關閉推送通知"
android:summaryOn="啟動推送通知"
android:title="推送通知" />
android:defaultValue="true"
android:dependency="@string/cbp_push_notification"
android:key="@string/cbp_push_sound"
android:summaryOff="關閉聲音"
android:summaryOn="開啟聲音"
android:title="推送聲音" />
android:defaultValue="true"
android:dependency="@string/cbp_push_notification"
android:key="@string/cbp_push_vibrate"
android:summaryOff="關閉震動"
android:summaryOn="開啟震動"
android:title="推送震動" />
然後在PreferenceActivity裡添加該資源
public class NotificationSettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
使用該配置要調用
SharedPreferences defaultSp = PreferenceManager.getDefaultSharedPreferences(context);
return defaultSp.getBoolean(context.getString(R.string.cbp_push_notification),true);