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();
}
这里我获得了Request令牌和所有东西,但是当重定向到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
,请帮忙。
答案 0 :(得分: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()
调用twiiter_MainActivity.this
方法,因为看起来你应该完全没有它。