Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share link via twitter in android?

In my app I need to share link for promo site via Facebook and twitter, in facebook we got something like "share dialog" or post bundle like

Request request = new Request(Session.getActiveSession(), "me/feed", bundle, HttpMethod.POST, 
       new Request.Callback(){
                @Override
                public void onCompleted(Response response) {
                    ...
                }
            });

but there are no twitter sdk for android(trully I use twitter4j) and no way to post bundle

so how to tweet link via twitter?

like image 274
user2331879 Avatar asked Oct 28 '14 13:10

user2331879


People also ask

How do I send my Twitter link?

Look at the Web address in your browser's address bar. This is your Twitter URL. Copy the link and share it with friends to lead them directly to your Twitter profile.

How do I make Twitter links open on Android?

Go to Settings > Apps > Twitter > under Defaults go to Set as default and turn off Open supported links.


1 Answers

If you send text with link like "Here is our link: http://stackoverflow.com" - twitter will understand it and get info from your link and show it - as I understand you need to see your recognized link in twitter feed. To post link you can make intent like @Adrian Sicaru or create your own custom dialog using asynctask with twitter4j as you mention:

@Override
protected Bundle doInBackground(Bundle... params) {
    Bundle args = params[0];
    Bundle result = new Bundle();

    String paramMessage = args.getString(MESSAGE);
    String paramLink = args.getString(LINK);

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey("your ConsumerKey");
    builder.setOAuthConsumerSecret("your ConsumerSecret");

    String accessToken = "your Token";
    String accessTokenSecret = "your Secret";

    TwitterFactory factory = new TwitterFactory(builder.build());
    mTwitter = factory.getInstance(new AccessToken(accessToken, accessTokenSecret));
    try {
        StatusUpdate status = new StatusUpdate(paramMessage);

        if (paramLink != null) {
            status = new StatusUpdate(paramMessage + " " + paramLink);
        }
        mTwitter.updateStatus(status);
    } catch (TwitterException e) {
        result.putString(RESULT_ERROR, e.getMessage());
    }
    return result;
}
like image 68
TribblerWare Avatar answered Sep 28 '22 23:09

TribblerWare