• Android之解决新浪微博登陆一次以后不用登录的问题


    做以下两个修改:
    1. 在com.foreveross.view.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);
            }

     

    2. 在com.foreveross.view.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());}

                         

  • 相关阅读:
    application manifest 中的requestedElevationLevel令牌
    【转载】讲故事谈.NET委托:一个C#睡前故事
    Sql Server排名函数
    SQL Server窗口函数的简单使用
    【转载】 [Server Error in Application ] WCF and HTTP Error 404.3 Not Found
    SystemColors.ActiveCaptionText在不同操作系统中的颜色不同
    问题:Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe"
    【转载】WCF and HTTP Error 404.3 Not Found
    【转载】cross apply & outer apply
    使用foreach来取代其它的循环结构
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2720988.html
Copyright © 2020-2023  润新知