首先创建/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);