Files
SNFLauncherMain_RockChip/mylibrary/src/main/java/com/android/util/SharedPreferencesUtil.java
2025-11-06 10:55:48 +08:00

92 lines
3.2 KiB
Java

package com.android.util;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesUtil {
/**文件名*/
private static final String SHARE_NAME="config";
/**参数名 IP*/
public static final String CONFIG_PARAM_IP="config_param_IP";
/**参数名 dort*/
public static final String CONFIG_PARAM_PORT="config_param_port";
/**参数名 联网认证是否通过*/
// public static final String CONFIG_PARAM_VERIFICATION="config_param_verification";
/**参数名 任务版本号*/
public static final String CONFIG_PARAM_TASK_VERISON_CODE="CONFIG_PARAM_TASK_VERISON_CODE";
/**参数名 设备是否在线*/
public static final String CONFIG_PARAM_ONLINE="config_param_online";
/**播放列表信息*/
public static final String CONFIG_PARAM_PLAYLIST="CONFIG_PARAM_PlayList";
/**激活次数*/
public static final String CONFIG_ACTIVATE_COUNT="CONFIG_ACTIVATE_COUNT";
/**是否要更新app信息到服务器*/
public static final String CONFIG_INIOR="CONFIG_INIOR";
public static String getSharePrefrencesString(Context context,String key){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
return sharedPreferences.getString(key,null);
}
public static void setSharePrefrencesString(Context context,String key,String value){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(key,value);
editor.commit();
}
public static void setSharePrefrencesInteger(Context context,String key,int value){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putInt(key,value);
editor.commit();
}
public static void setSharePrefrencesLong(Context context,String key,Long value){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putLong(key,value);
editor.commit();
}
public static void setSharePrefrencesBoolean(Context context,String key,boolean value){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putBoolean(key,value);
editor.commit();
}
public static int getSharePrefrencesInteger(Context context,String key){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
return sharedPreferences.getInt(key,-1);
}
public static long getSharePrefrencesLong(Context context,String key){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
return sharedPreferences.getLong(key,0);
// return 0;
}
public static boolean getSharePrefrencesBoolean(Context context,String key){
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
return sharedPreferences.getBoolean(key,false);
}
}