Back to project page Peterson.
The source code is released under:
GNU General Public License
If you think the Android project Peterson listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/******************************************************************************* * Copyright (c) 2013 Zheng Sun.//from www . ja v a 2 s . com * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Zheng Sun - initial API and implementation ******************************************************************************/ package tv.huohua.peterson.social; import com.weibo.sdk.android.Oauth2AccessToken; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class WeiboAccessTokenKeeper { private static final String PREFERENCES_NAME = "com_weibo_sdk_android"; public static void keepAccessToken(final Context context, final Oauth2AccessToken token) { final SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); final Editor editor = pref.edit(); editor.putString("token", token.getToken()); editor.putLong("expiresTime", token.getExpiresTime()); editor.commit(); } public static void clear(final Context context) { final SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); final Editor editor = pref.edit(); editor.clear(); editor.commit(); } public static Oauth2AccessToken readAccessToken(final Context context) { final Oauth2AccessToken token = new Oauth2AccessToken(); final SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); token.setToken(pref.getString("token", "")); token.setExpiresTime(pref.getLong("expiresTime", 0)); return token; } }