偏好设置

来源:互联网 发布:软件测试的案例 编辑:程序博客网 时间:2024/04/28 19:22
public class SPUtil {

private static Editor editor;
private SharedPreferences sp;

public SPUtil(String spName){
sp = MyApp.context.getSharedPreferences(spName, Context.MODE_PRIVATE);
editor = sp.edit();
}
/**
* 是否接受通知
* @return
*/
public boolean isAcceptNotify(){
return sp.getBoolean("notify", true);
}
/**
* 是否允许声音
* @return
*/
public boolean isAllowSound(){
return sp.getBoolean("sound", true);
}
/**
* 是否允许震动
* @return
*/
public boolean isAllowVibrate(){
return sp.getBoolean("vibrate", true);
}
/**
* 设置是否允许接受通知
* @param flag
*/
public void setAcceptNotify(boolean flag){
editor.putBoolean("notify", flag);
editor.commit();
}
/**
* 设置是否允许声音
* @param flag
*/
public void setAllowSound(boolean flag){
editor.putBoolean("sound", flag);
editor.commit();
}
/**
* 设置是否允许震动
* @param flag
*/
public void setAllowVibrate(boolean flag){
editor.putBoolean("vibrate", flag);
editor.commit();
}
}
0 0
原创粉丝点击