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
来自Null
,Intent
请帮助。