How to transfer http image directly to twitter in android?

So far, I searched in the postoffflow post, and I can share the text directly with twitter without showing a popup dialog for share.That means that when I click the button, it is redirected directly to the Twitter application and shows the text.

My only problem is that I need to transfer the http image directly to twitter.

Below I posted the code I have 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 this code above, the text is displayed correctly on twitter. But the image is displayed in http-url.

Does anyone know how to transfer the image directly to the Twitter application without showing the link.

+6
source share
4 answers

You can use the TwitterComposer dialog.

Here is a 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; } 
+7
source

That's what you need

 intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file); 
0
source

you can try this work for me

Uri Image:

 File myImageFile = new File("/path/to/image"); Uri myImageUri = Uri.fromFile(myImageFile); 

Intent builder

 TweetComposer.Builder builder = new TweetComposer.Builder(this) .text("just setting up my Fabric.") .image(myImageUri); builder.show(); 

Add this to your build.gradle dependencies:

 dependencies { compile('com.twitter.sdk.android:tweet-composer: 1.0.5@aar ') { transitive = true; } } 
0
source

To call:

 new PostPicture(MyActivity.this).execute("IMAGE_URL"); 

Picture:

 private class PostPicture extends AsyncTask<String, Void, File> { private final Context context; public PostPicture(Context context) { this.context = context; } @Override protected File doInBackground(String... params) { FutureTarget<File> future = Glide.with(getApplicationContext()) .load(params[0]) .downloadOnly(600, 600); File file = null; try { file = future.get(); } catch (Exception e) { e.printStackTrace(); } return file; } @Override protected void onPostExecute(File result) { if (result == null) { return ; } Uri uri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName(), result); postIt(uri); } private void postIt(Uri result) { TweetComposer.Builder builder = new TweetComposer.Builder(this) .text("Post Image from URl.") .image(result); builder.show(); } } 
0
source

All Articles