0

WebView重定向到 Twitter_Activity时无法获取 Uri

LoginButton点击

private void loginToTwitter() {
        new AsyncTask<Void, Void, Void>(){
            @Override
            protected void onPreExecute() {
            super.onPreExecute();
                pbr =  new ProgressDialog(Twiiter_MainActivity.this);
                pbr.setMessage("Loding..");
                pbr.show();         
                checklogin = false;
            }

            @Override
            protected Void doInBackground(Void... params) {
                if (!isTwitterLoggedInAlready()) {
                    ConfigurationBuilder builder = new ConfigurationBuilder();
                    builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
                    builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
                    Configuration configuration = builder.build();
                    TwitterFactory factory = new TwitterFactory(configuration);
                    twitter = factory.getInstance();
                     try {
                        requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);                      
                        allReadynew  = true;
                    } catch (TwitterException e) {
                        e.printStackTrace();
                    }

                } else {
                    // user already logged into twitter                 

                     checklogin = true;
                }
                return null;
            }
            protected void onPostExecute(Void result) {
                    try {                                           
                     if(pbr!=null){
                         pbr.dismiss();
                     }
                     Twiiter_MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
                     } catch (Exception e) {
                     e.printStackTrace();                    
                     }              


            };
        }.execute();
    }

我在这里得到了请求令牌和所有东西,但是webview在登录 Twitter 帐户后重定向到然后。回到Activity我的下面code执行。

@Override
    protected void onResume() {
        super.onResume();
        init();
    }


private void init(){

        boolean chkNet = HotSpotSettings.isNetworkAvailable(mcontext);
        if (chkNet == true) {
            // Check if twitter keys are set
            if(TWITTER_CONSUMER_KEY.trim().length() == 0 || TWITTER_CONSUMER_SECRET.trim().length() == 0){
                // Internet Connection is not present
                UtilityCommon.showDialogwithTitle(mcontext,"Please set your twitter oauth tokens first!");          
                return;
            }

            if (isTwitterLoggedInAlready()) {               
               uri = getIntent().getData();
                    // Here I m getting Null value from Uri

            }           
        }else{
            UtilityCommon.showDialogwithTitle(mcontext, HotSpotSettings.NO_NETWORK);
            return;
        }       
    }

uri来自NullIntent请帮助。

4

1 回答 1

2

我会尝试重写这一行:

Twiiter_MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));

对此:

Intent intent = new Intent(CurrentActivity.this, targetActivity.class);
intent.setData(Uri.parse(requestToken.getAuthenticationURL());
startActivity(intent);

没有看到你班上的其他人,我不明白你为什么要调用startActivity()from 方法twiiter_MainActivity.this,因为看起来你应该完全有能力没有它。

于 2013-04-19T09:02:57.057 回答