SharedPreferenceUtils.java
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.hhmedic.sdk.demo;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferenceUtils {
private static final String PREFERENCE_NAME = "HH_SDK_DEMO";
public static void setValue(Context context,String key,String value) {
SharedPreferences.Editor editor = getEditor(context);
editor.putString(key, value);
editor.apply();
}
public static void setValue(Context context,String key,Boolean value) {
SharedPreferences.Editor editor = getEditor(context);
editor.putBoolean(key, value);
editor.apply();
}
public static String getStringValue(Context context, String key){
return getSharePreference(context).getString(key, "");
}
public static boolean getBooleanValue(Context context,String key, boolean defaultValue) {
return getSharePreference(context).getBoolean(key, defaultValue);
}
private static SharedPreferences getSharePreference(Context context) {
return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
}
private static SharedPreferences.Editor getEditor(Context context) {
SharedPreferences preferences = getSharePreference(context);
return preferences.edit();
}
}