Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share http image directly to twitter in android?

So Far I searched in stackoverflow post and I can share the text directly to twitter without showing the popup dialog for share.That means when I click the button it is directly redirect to twitter app and shows the text.

My only issue is I have to share http image directly to twitter.

Below I have posted the code what I tried so far:

UsersAdapter.java:

// Create intent using ACTION_VIEW and a normal Twitter url:
        String tweetUrl = String.format("https://twitter.com/intent/tweet?text=%s&url=%s",
                urlEncode(strShareText), 
                urlEncode(strShareImageUrl));
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));

        // Narrow down to official Twitter app, if available:
        List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
        for (ResolveInfo info : matches) {
            if (info.activityInfo.packageName.toLowerCase().startsWith("com.twitter")) {
                intent.setPackage(info.activityInfo.packageName);
            }
        }

        context.startActivity(intent);

In that above code Text is showing correctly in twitter.But image is showing in http url.

Anyone know how to share the image directly to twitter app without showing link.

like image 277
Steve Avatar asked Feb 17 '16 12:02

Steve


People also ask

How do I share a picture on twitter from a website?

As you might have guessed, you have to issue a tweet and attach the image before you'll be able to get that link. Create a tweet as you normally would, either using your sharing buttons or tweeting on twitter.com natively, and drag an image from your desktop into the tweet to attach and send it.

How do you Tweet a photo?

Use the compose tweet button to create a new tweet. Click the add media button. Select a photo, video, or GIF from your computer, and click open.


1 Answers

You can use TwitterComposer dialog.

Here is sample code.

TweetComposer.Builder builder = new TweetComposer.Builder(mActivity)
                .text("hello text");
                .image(Uri.parse("https://media-mediatemple.netdna-ssl.com/wp-content/uploads/2016/01/07-responsive-image-example-castle-7-opt.jpg"));
builder.show();

Add dependencies in gradle file

compile('com.twitter.sdk.android:twitter:1.8.0@aar') {
        transitive = true;
}
like image 99
Niranj Patel Avatar answered Oct 05 '22 22:10

Niranj Patel