We have an application which supports normal login using a valid email id as well as using Twitter. We are supporting post tweets using our application.

Before posting tweet I m checking for Twitter session. If there is no active session, I m navigating user to Twitter login screen by calling TwitterAuthClient.authorize() method. After authorizing the user able to see the Tweet composer box where user can compose and post tweet. The flow is working properly most of the times. But sometimes the Twitter SDK is opening the Twitter home screen https://drive.google.com/file/d/0Bz670htOa0h6X1NPajNLSS1YVzNvN2F1VWh2WEhzR0N0YTc0/view?usp=sharing instead of https://drive.google.com/file/d/0Bz670htOa0h6U0xLT0hxcUUyYVUtVXVfV1RTSTNEWFo3LThF/view?usp=sharing screen. Due to this the callback is not coming back to my application after sign in. So, I m not able to Tweet.

NOTE: Twitter app is installed in my device and there is not active Twitter session present.

Code:

private void postViaTwitter() {
  if (Twitter.getSessionManager().getActiveSession() != null ||
    !(Utils.isAppPresent(AppConstant.TWITTER_PACKAGE_NAME, this))) {
URL url = null;
try {
    url = new URL(UrlUtils.APP_URL);

    TweetComposer.Builder tweetComposer = new TweetComposer.Builder(this)
            .text(getString(R.string.share_content_description))
            .url(url);
    tweetComposer.show();

} catch (MalformedURLException e) {
    Log.e("Exception", e.getMessage(), e);
}
} else {
 loginAndShareUsingTwitter();
   }
}

private void loginAndShareUsingTwitter() {
TwitterAuthClient client = new TwitterAuthClient();
    client.authorize(this, new com.twitter.sdk.android.core.Callback<TwitterSession>() {
    @Override
    public void success(Result<TwitterSession> result) {
        if (result != null) {
            TwitterSession session = result.data;
            if (session != null) {
                postViaTwitter();
            }
        }
    }

    @Override
    public void failure(TwitterException exception) {
    }
});

}

0

There are 0 best solutions below