AuthorizeActivity类作以下修改保存access_token:
public void onComplete(Bundle values) {
String token = values.getString("access_token");
String expires_in = values.getString("expires_in");
mToken.setText("access_token : " + token + " expires_in: "
+ expires_in);
//必须加这句
//Utility.setAuthorization(new Oauth2AccessTokenHeader());
//保用shareperenced保存accesstoken
SharedPreferences settings = getSharedPreferences("saveToken", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("access_token", token);
editor.commit();
AccessToken accessToken = new AccessToken(token, CONSUMER_SECRET);
accessToken.setExpiresIn(expires_in);
Weibo.getInstance().setAccessToken(accessToken);
Intent intent = new Intent();
intent.setClass(AuthorizeActivity.this, HomePageActivity.class);
startActivity(intent);
}
AuthorizeActivity类的onCreate方法作以下修改:
SharedPreferences settings = getSharedPreferences("saveToken", 0);
if(settings.getString("access_token", null) != null){
Utility.setAuthorization(new Oauth2AccessTokenHeader());
String token = settings.getString("access_token","");
AccessToken accessToken = new AccessToken(token, CONSUMER_SECRET);
Weibo.getInstance().setAccessToken(accessToken);
Intent intent = new Intent();
intent.setClass(AuthorizeActivity.this, HomePageActivity.class);
startActivity(intent);
}
else{
weibo.authorize(AuthorizeActivity.this,
new AuthDialogListener());}
欢迎大家一起加入Android群,讨论技术问题,共同进步。QQ群:272655313