Android solves the problem that Sina Weibo does not need to log on after one login

Source: Internet
Author: User
Make the following two changes:
1. In the com. foreveross. View. authorizeactivity class, modify and save the 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 );


// This sentence must be added
// Utility. setauthorization (New oauth2accesstokenheader ());
// Use shareperenced to save the accesstoken
Sharedpreferences settings = getsharedpreferences ("savetoken", 0 );
Sharedpreferences. Editor editor = settings. Edit ();
Editor. putstring ("access_token", token );
Editor. Commit ();

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 );
}

 

2.Modify the oncreate method of the COM. foreveross. View. authorizeactivity class as follows:

Sharedpreferences settings = getsharedpreferences ("savetoken", 0 );
If (settings. getstring ("access_token", null )! = NULL ){
Utility. setauthorization (New oauth2accesstokenheader ());

String token = settings. getstring ("access_token ","");

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 ());}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.