Share image from URL via Twitter app - Android - android

I'm trying to share some text and image via the Twitter app. The image source is a web url.
Below is my code:
sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url+"");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("http://example.com/images/thumbs/file_name.jpg"));
But only the text is getting shared via the Twitter app. I also get a message saying "Image could not be loaded". What is the problem with this code?

Sourav, I think you must download the picture before sharing it. You can do it manually, or maybe you could use a library like this. You can find inside the library's repository easy documentation about how to set up and use it.
After you have downloaded the picture you can follow this method:
private Intent shareIntent(String bookmark_url, String imagePath){
sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url);
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
return sharingIntent;
}
If you simply want to simulate "Parsing image on the fly", delete it after sharing.
Hope this helps you!

Related

I made an app from a website and I would like to How to share the current URL from the current post or page

Does anybody can help me?
I have a website and I converted it using android studio into an app and I would like to implement a share button to share the current URL, not only a fixed URL.
I have the share button done, but it only shares the URL I want. Thanks
On button action you must capture the url
String HiUrl = webView.getUrl();
and set the string in the intent
yourIntent.putExtra(Intent.EXTRA_TEXT, HiUrl ");
based on your code, I found the answer:
it's not Intent.putExtra(Intent.EXTRA_TEXT, Hiurl);
its share.putExtra(Intent.EXTRA_TEXT, Hiurl);
without quotes.
if(id==R.id.mnShare)
{
Intent share = new Intent(android.content.Intent.ACTION_SEND);
String Hiurl = MYWEBVIEW.getUrl();
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.putExtra(Intent.EXTRA_SUBJECT, "Site");
share.putExtra(Intent.EXTRA_TEXT, Hiurl);
startActivity(Intent.createChooser(share, "share with"));
}

Facebook share doesn't work correctly

I am trying to share a text containing a link via facebook.
My code work perfectly with the facebook messenger application. But not via Facebook app.
In Facebook app i am getting a sharing view with an empty edittext. I Don't want to integrate facebook api and give sharing authorisation. I don't want to do that. I think it can be done only via extras and intent.
My sharing code:
private void ShareWebView(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, mTitle);
startActivity(Intent.createChooser(intent, "Share with"));
}
You cannot. See Android and Facebook share intent
And especially this link provided in one of the comment : http://developers.facebook.com/bugs/332619626816423
Walkaround: If you do not want to implement it using android SDK
and you want to use
private void ShareWebView(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, mTitle); // MUST contain 1 url
startActivity(Intent.createChooser(intent, "Share with"));
}
make sure that mTitle contains one LINK.
Why to do that: Although the fact that facebook doesn't work properly it grubs the first url or look like url from the mTitle and post-it as share url. It also automatically catch a subtitle and a photo from that url so the post/share is quite acceptable most of the time avoiding long code implementations!

Instagram from Android open on certain user and add caption to uploaded image

Instagram for Android is very limited, from what I have seen so far. My scenario is simple: allow the user to edit a picture and when he clicks on Send:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Then with queryIntentActivities() I search to see if Instagram is installed. If it is I send the path of my image to be uploaded:
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path to myfile.png"));
share.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
share.putExtra(Intent.EXTRA_SUBJECT, "Sample subject");
share.putExtra(Intent.EXTRA_TEXT, "Sample text");
share.putExtra(Intent.EXTRA_TITLE, "Sample title");
The result: the image is uploaded using Instagram app (of course if I am logged in), but I can't add a Caption to it. None of the putExtra has any effect. So, is there any way to add a caption as intent parameter ?
And the other question, is it possible to open Instagram app with a certain user name filled in ?
It looks as if Instagram's Android App ignores EXTRA_TEXT, EXTRA_SUBJECT and EXTRA_TITLE, so it seems that adding a caption while uploading an image is not possible. By the way, you can try different approaches to check if it ignores those extras in every case:
OPTION #1: Changing the MIME type.
You are setting the MIME type to "image/jpeg". Try using "image/" or "/*" to check if their app doesn't ignore those extras.
share.setType("image/*");
or
share.setType("*/*");
OPTION #2:
As you are sending multiple MIME types (image and text), maybe their app is expecting ACTION_SEND_MULTIPLE instead of ACTION_SEND.
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
OPTION #3: Use MediaStore.Images.Media.insertImage(ContentResolver cr, String imagePath, String name, String description) function:
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), "file:///" + path to myfile.png", "Sample title", "Sample description")));
share.setType("image/jpeg");
share.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
OPTION #4: Post your issue in their developer forum, although there are similar questions that remain unsolved:
https://groups.google.com/forum/?fromgroups#!searchin/instagram-api-developers/caption$20action_send/instagram-api-developers/PJDuG2sTDlM/6bno5dZmoTEJ
https://groups.google.com/forum/?fromgroups#!searchin/instagram-api-developers/caption/instagram-api-developers/7XUKm9HSAdg/rJbdSnOmXacJ
And don't forget to come back and tell us their answer!
It looks like Instagram has updated their app to accept EXTRA_TEXT to add a caption. If the user has an updated version of Instagram (July 1, 2014 version or later) you can post an image and add a caption with the following code:
Intent instagram = new Intent(android.content.Intent.ACTION_SEND);
instagram.setType("image/*");
instagram.putExtra(Intent.EXTRA_STREAM, [URI of photo]);
instagram.putExtra(Intent.EXTRA_TEXT, [Text of caption]);
instagram.setPackage(instagramPackageName);
startActivity(instagram);
Users with older versions will still get the image, but not have the caption be pre populated.
This code is assuming you have already been through the auth flow.

Android: Share Text & Image (URL) Via Intent

I am trying to share text with an image via an ACTION_SEND intent. The catch is that the image is represented by a URL, not a local URI. The code I currently have is:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, text); // <- String
shareIntent.putExtra(Intent.EXTRA_STREAM, url); // <- URL object
Now I've tried a few variations on this. I've tried with setType("image/*"), I've tried parsing a Uri from the URL, I've tried passing the URL string itself, etc. Nothing so far seems to work. However, when sending to twitter I do see the text, just not the image.
Edit:
Apparently the original description was not helpful enough, so....when I launch the above intent it successfully opens a chosen application like Twitter, or Facebook, or Gmail, or Text Messaging, but an image appars in NONE of these apps. The text appears in Twitter - I can't remember if the text appears elsewhere, but my focus at this moment is on the image part anyway.
You won't be able to share on Facebook in that way because of Facebook's policy as it says in a known bug:
API does not support pre-filling the message for users
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.putExtra(Intent.EXTRA_TEXT,videoPos);
sharingIntent.putExtra(Intent.EXTRA_STREAM,getImageUri(getApplicationContext(), bitmap));

Android Share Text on Facebook instead of Link

I am working on Text Sharing on From my Android Application . I have used the following code.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String text="http://google.com";
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,text);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Message");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
If I will this code means it shares link correctly and shows like following image !
Attached Image
When I am using normal text like "sample content" means it is not accepting and showing the text .... I need to share the text instead of that link .. please help me ...
Its working correctly for Gmail and Twitter also.
Waiting for better response..... Thanks in Advance
This is a limitation with the (stupid) Facebook app. They know about it, but apparently don't want to fix it.
Your only option is to implement Facebook sharing using their API.

Categories

Resources