Java Code Examples for android.content.SharedPreferences.Editor#putString()

The following examples show how to use android.content.SharedPreferences.Editor#putString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharedPreferencesUtils.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 
 * @author zhoufeng
 * @createtime 2015-3-30 下午2:59:33
 * @Decription 向SharedPreferences添加信息
 *
 * @param context 上下文
 * @param SharedPreferName SharedPreferences的名称
 * @param type 数据的类型
 * @param key 数据的名称
 * @param value 数据的值
 */
public static void saveSharedPreferInfo(Context context, String SharedPreferName, String type, String key,
		Object value) {
	SharedPreferences userPreferences;
	userPreferences = context.getSharedPreferences(SharedPreferName, Context.MODE_PRIVATE);
	Editor editor = userPreferences.edit();

	if ("String".equals(type)) {
		editor.putString(key, (String) value);
	} else if ("Integer".equals(type)) {
		editor.putInt(key, (Integer) value);
	} else if ("Boolean".equals(type)) {
		editor.putBoolean(key, (Boolean) value);
	} else if ("Float".equals(type)) {
		editor.putFloat(key, (Float) value);
	} else if ("Long".equals(type)) {
		editor.putLong(key, (Long) value);
	}
	editor.commit();
}
 
Example 2
Source File: PreferencesUtil.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 设置Key对应的String值 */
public static boolean setStringValue(Context context,String key, String value) {
	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
	Editor editor = prefs.edit();
	editor.putString(key, value);
	return editor.commit();
}
 
Example 3
Source File: EventPreferencesRadioSwitch.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void loadSharedPreferences(SharedPreferences preferences)
{
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_EVENT_RADIO_SWITCH_ENABLED, _enabled);
    editor.putString(PREF_EVENT_RADIO_SWITCH_WIFI, String.valueOf(this._wifi));
    editor.putString(PREF_EVENT_RADIO_SWITCH_BLUETOOTH, String.valueOf(this._bluetooth));
    editor.putString(PREF_EVENT_RADIO_SWITCH_MOBILE_DATA, String.valueOf(this._mobileData));
    editor.putString(PREF_EVENT_RADIO_SWITCH_GPS, String.valueOf(this._gps));
    editor.putString(PREF_EVENT_RADIO_SWITCH_NFC, String.valueOf(this._nfc));
    editor.putString(PREF_EVENT_RADIO_SWITCH_AIRPLANE_MODE, String.valueOf(this._airplaneMode));
    editor.apply();
}
 
Example 4
Source File: ProfileManager.java    From android with GNU General Public License v3.0 5 votes vote down vote up
public static void setConntectedVpnProfileDisconnected(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    Editor prefsedit = prefs.edit();
    prefsedit.putString(LAST_CONNECTED_PROFILE, null);
    prefsedit.apply();

}
 
Example 5
Source File: SpUtils.java    From Last-Launcher with GNU General Public License v3.0 5 votes vote down vote up
SpUtils putString(String key, String value) {
    if (mPref != null) {
        Editor editor = mPref.edit();
        editor.putString(key, value);
        editor.apply();
        return this;
    } else throw new RuntimeException("First Initialize context");
}
 
Example 6
Source File: UserInfo.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void setLoginInfo(boolean isLogin, String name, String sessionId, String recommandURL){
	this.isLogin = isLogin;
	this.name = name;
	this.sessionId = sessionId;
	this.recommandURL = recommandURL;
	
	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
	Editor editor = sp.edit();
	editor.putBoolean(IS_LOGIN, isLogin);
	editor.putString(USER_NAME, name);
	editor.putString(USER_SESSION_ID, sessionId);
	editor.putString(USER_RECOMMAND_URL, recommandURL);
	editor.commit();
}
 
Example 7
Source File: Utils.java    From ACDD with MIT License 5 votes vote down vote up
/**
 * save OpenAtlas runtime info to sharedPreference
 **/
public static void saveAtlasInfoBySharedPreferences(Application application) {
    Map<String, String> concurrentHashMap = new ConcurrentHashMap<String, String>();
    concurrentHashMap.put(getPackageInfo(application).versionName, "dexopt");
    SharedPreferences sharedPreferences = application.getSharedPreferences(OpenAtlasInternalConstant.OPENATLAS_CONFIGURE, Context.MODE_PRIVATE);
    if (sharedPreferences == null) {
        sharedPreferences = application.getSharedPreferences(OpenAtlasInternalConstant.OPENATLAS_CONFIGURE, Context.MODE_PRIVATE);
    }
    Editor edit = sharedPreferences.edit();
    for (String key : concurrentHashMap.keySet()) {
        edit.putString(key, concurrentHashMap.get(key));
    }
    edit.commit();
}
 
Example 8
Source File: EventPreferencesPeripherals.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void loadSharedPreferences(SharedPreferences preferences)
{
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_EVENT_PERIPHERAL_ENABLED, _enabled);
    editor.putString(PREF_EVENT_PERIPHERAL_TYPE, String.valueOf(this._peripheralType));
    editor.apply();
}
 
Example 9
Source File: EventPreferencesNFC.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void loadSharedPreferences(SharedPreferences preferences)
{
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_EVENT_NFC_ENABLED, _enabled);
    editor.putString(PREF_EVENT_NFC_NFC_TAGS, _nfcTags);
    editor.putBoolean(PREF_EVENT_NFC_PERMANENT_RUN, this._permanentRun);
    editor.putString(PREF_EVENT_NFC_DURATION, String.valueOf(this._duration));
    editor.apply();
}
 
Example 10
Source File: SplashActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
private void init() {
    Fabric.with(this, new Crashlytics());
    SharedPreferences pref = getSharedPreferences("LetvActivity", 32768);
    if (!pref.contains("isFirstIn")) {
        String str = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis()));
        Editor editor = pref.edit();
        editor.putString("firstRunAppTime", str);
        editor.putBoolean("isFirstIn", false);
        editor.commit();
    }
    if (BaseApplication.getAppStartTime() == 0) {
        BaseApplication.setAppStartTime(System.currentTimeMillis());
    }
    PreferencesManager.getInstance().setLesoNotification(false);
    boolean isNewApp = isNewAppVersion4Leso(PreferencesManager.getInstance().getVersionCode4Leso(), LetvUtils.getClientVersionCode());
    if (isNewApp) {
        LogInfo.log("Emerson", "--------------------isNewApp = " + isNewApp);
        PreferencesManager.getInstance().setIsShack(false);
    }
    initLesoIcon_notification(this);
    staticsCrashInfo();
    LetvApplication.getInstance().setIsShack(PreferencesManager.getInstance().isShack());
    LetvHttpConstant.setDebug(LetvConfig.isDebug());
    getDefaultImage(this);
    LetvUtils.setUa(this);
    JarUtil.sHasApplyPermissionsSuccess = true;
    if (ApkManager.getInstance().getPluginInstallState("com.letv.android.lite") != 1) {
        LogInfo.log("plugin", "重新启动了乐视视频,且liteapp之前未成功安装,重试重新下载");
        JarUtil.updatePlugin(this, 1, true);
    }
    if (LetvApplication.getInstance().hasInited()) {
        onAppInited();
    } else {
        startAppInitThread();
    }
    new RetentionRateUtils().doRequest(1);
    if (LetvConfig.isUmeng()) {
        AnalyticsConfig.setChannel(LetvConfig.getUmengID());
    }
}
 
Example 11
Source File: PreferencesManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean saveLatestLaunchTime() {
    long t = System.currentTimeMillis();
    String date = StringUtils.timeString(t);
    String minutes = StringUtils.timeStringByMinutes(t);
    SharedPreferences sp = context.getSharedPreferences(FORCE_ALERT, 0);
    if (sp.getLong(PREF_CURRENTTIMEMILLIS, 0) != 0 && t - sp.getLong(PREF_CURRENTTIMEMILLIS, 0) < 300000) {
        return false;
    }
    Editor editor = sp.edit();
    editor.putLong(PREF_CURRENTTIMEMILLIS, t);
    editor.putString(PREF_LAUNCH_DATE, date);
    editor.putString(PREF_LAUNCH_MINUTE, minutes);
    editor.commit();
    return true;
}
 
Example 12
Source File: EventPreferencesWifi.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void loadSharedPreferences(SharedPreferences preferences)
{
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_EVENT_WIFI_ENABLED, _enabled);
    editor.putString(PREF_EVENT_WIFI_SSID, this._SSID);
    editor.putString(PREF_EVENT_WIFI_CONNECTION_TYPE, String.valueOf(this._connectionType));
    editor.apply();
}
 
Example 13
Source File: PreferencesUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a string preference value.
 * 
 * @param context the context
 * @param keyId the key id
 * @param value the value
 */
@SuppressLint("CommitPrefEdits")
public static void setString(Context context, int keyId, String value) {
  SharedPreferences sharedPreferences = context.getSharedPreferences(
      Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
  Editor editor = sharedPreferences.edit();
  editor.putString(getKey(context, keyId), value);
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
 
Example 14
Source File: SPUtils.java    From MousePaint with MIT License 5 votes vote down vote up
/**
 * 缓存信息
 * @param cacheName	存入名字
 * @param obj	对象
 */
public static void saveObject(String cacheName,Object obj){
	Editor e = context.getSharedPreferences(APP_ID, Context.MODE_PRIVATE).edit();
       String json =  gson.toJson(obj);
	e.putString(cacheName, json);
	e.commit();
}
 
Example 15
Source File: SPHelper.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
public static void setString(String key, String value) {
    SharedPreferences sp = mContext.getSharedPreferences(
            SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    editor.putString(key, value);
    editor.apply();
}
 
Example 16
Source File: SharePreferenceUtil.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public static void setString(Context context, String key, String value) {
    SharedPreferences preferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putString(key, value);
    editor.commit();
}
 
Example 17
Source File: MainActivity.java    From shadowsocks-android-java with Apache License 2.0 4 votes vote down vote up
void setProxyUrl(String ProxyUrl) {
    SharedPreferences preferences = getSharedPreferences("shadowsocksProxyUrl", MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putString(CONFIG_URL_KEY, ProxyUrl);
    editor.apply();
}
 
Example 18
Source File: PreferenceUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public void setSongSortOrder(String sortOrder) {
    Editor edit = this.mPreferences.edit();
    edit.putString(SONG_SORT_ORDER, sortOrder);
    edit.apply();
}
 
Example 19
Source File: PreferencesManager.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setContinuePayDateTime(String datetime) {
    Editor editor = context.getSharedPreferences(SETTINGS, 4).edit();
    editor.putString("continue_pay_datetime", datetime);
    editor.putInt("expire_days", -101);
    editor.commit();
}
 
Example 20
Source File: PreferenceUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public void setSongSortOrder(String sortOrder) {
    Editor edit = this.mPreferences.edit();
    edit.putString(SONG_SORT_ORDER, sortOrder);
    edit.apply();
}