123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package com.example.myapplication.utils;
- import android.text.TextUtils;
- import com.example.myapplication.MyApplication;
- public class SharePreferHelper {
- /**
- * 获取sessionId
- *
- * @return sessionId
- */
- public static String getSessionId() {
- return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID, "");
- }
- /**
- * 清除 sessionId
- */
- public static void clearSessionId() {
- SPUtils.remove(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID);
- }
- /**
- * 保存sessionId
- *
- * @param sessionId
- */
- public static void setSessionId(String sessionId) {
- if (TextUtils.isEmpty(sessionId)) {
- return;
- }
- SPUtils.put(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID, sessionId);
- }
- /**
- * 保存用户手机号码
- *
- * @param phoneNumber
- */
- public static void setUserPhoneNumber(String phoneNumber) {
- if (TextUtils.isEmpty(phoneNumber)) {
- return;
- }
- SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_NAME, phoneNumber);
- }
- /**
- * 获取用户手机号码
- *
- * @return phoneNumber
- */
- public static String getUserPhoneNumber() {
- return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_NAME, "");
- }
- /**
- * 保存用户密码
- *
- * @param password
- */
- public static void setPassword(String password) {
- if (TextUtils.isEmpty(password)) {
- return;
- }
- SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD, password);
- }
- /**
- * 获取用户密码
- *
- * @return password
- */
- public static String getPassword() {
- return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD, "");
- }
- /**
- * 保存用户邮箱地址
- *
- * @param mailAddress 地址
- */
- public static void setUserMail(String mailAddress) {
- if (TextUtils.isEmpty(mailAddress)) {
- return;
- }
- SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_MAIL, mailAddress);
- }
- /**
- * 获取用户邮箱地址
- *
- * @return mailAddress
- */
- public static String getUserMail() {
- return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_MAIL, "");
- }
- /**
- * 清除 password
- */
- public static void clearPassword() {
- SPUtils.remove(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD);
- }
- /**
- * 退出登录
- */
- public static void loginOut() {
- clearSessionId();
- clearPassword();
- }
- }
|