How to Share Photo with Caption via Android Share Intent on Facebook

How to share photo with CAPTION via Android share intent on Facebook?

Add this line to your existing codes:

shareCaptionIntent.putExtra(Intent.EXTRA_TITLE, "my awesome caption in the EXTRA_TITLE field");

There is no clearly defined differences among EXTRA_TITLE, EXTRA_SUBJECT and EXTRA_TEXT. So there is no clear share protocol. We could always try them all. :-)

Android: How to share image with text on facebook via intent?

The newest Facebook versions doesn't allow you to share text using intents. You have to use the Facebook SDK to do it - to make that simple, use the Facebook SDK + Android Simple Facebook (https://github.com/sromku/android-simple-facebook). Using the library, your code would be like this (extracted from the Simple Facebook site):

Publish feed

Set OnPublishListener and call for:

  • publish(Feed, OnPublishListener) without dialog.
  • publish(Feed, true, OnPublishListener) with dialog.

Basic properties

  • message - The message of the user
  • name - The name of the link attachment
  • caption - The caption of the link (appears beneath the link name)
  • description - The description of the link (appears beneath the link caption)
  • picture - The URL of a picture attached to this post. The picture must be at least 200px by 200px
  • link - The link attached to this post

Initialize callback listener:

OnPublishListener onPublishListener = new OnPublishListener() {
@Override
public void onComplete(String postId) {
Log.i(TAG, "Published successfully. The new post id = " + postId);
}

/*
* You can override other methods here:
* onThinking(), onFail(String reason), onException(Throwable throwable)
*/
};

Build feed:

Feed feed = new Feed.Builder()
.setMessage("Clone it out...")
.setName("Simple Facebook for Android")
.setCaption("Code less, do the same.")
.setDescription("The Simple Facebook library project makes the life much easier by coding less code for being able to login, publish feeds and open graph stories, invite friends and more.")
.setPicture("https://raw.github.com/sromku/android-simple-facebook/master/Refs/android_facebook_sdk_logo.png")
.setLink("https://github.com/sromku/android-simple-facebook")
.build();

Publish feed without dialog:

mSimpleFacebook.publish(feed, onPublishListener);

Publish feed with dialog:

mSimpleFacebook.publish(feed, true, onPublishListener);


Update on 14 December 2015


according to New Facebook SDK.

facebook-android-sdk:4.6.0

It's very Simple.

1. create Provider in Android.manifest.xml

<provider
android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />

2. Create Your Share Intent with Data.

ShareHashtag shareHashTag = new ShareHashtag.Builder().setHashtag("#YOUR_HASHTAG").build();
ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
.setShareHashtag(shareHashTag)
.setQuote("Your Description")
.setContentUrl(Uri.parse("image or logo [if playstore or app store url then no need of this image url]"))
.build();


3. Show The Share Dialog

ShareDialog.show(ShowNavigationActivity.this,shareLinkContent);


That's It.

Share image in Facebook programmatically from Android app via Intent

Could the reason be some security restrictions, e.g. The FB app does not have rights to access the image in the application folder even though it is invoked from an intent?

Correct. That image is on internal storage for your app, which is private to your app.

If so, what would be a proper location for an image shared between the apps?

You can stick with internal storage, though you will need to use a FileProvider, perhaps with my LegacyCompatCursorWrapper, to serve the file. This sample app demonstrates this, albeit with a PDF rather than an image.

Or, put the file on external storage.

Shall I use something like this: how to share image to facebook via intent

You could, though that would seem to be overkill, compared to using FileProvider.

Android : How to share photo with CAPTION via Android share intent on Facebook?

Facebook does not use the conventional sharing-through-intent paradigm. The text you supply to share as caption is actually being used as the thumbnail link to share an online image or video.

This leaves no room for the caption. So don't waste you time looking for it.

You have to use Facebook API to share both image and the caption. Go to facebook developer page where you can find packages you'll need to include in your app (look for facebook.jar or similar).

Share Image and Text to Facebook on android

Was able to do this my self with the current Facebook SDK (3.14.1 at the time) with no login and I made it into a share intent for adding to the chooser list.

I have a demo project at https://github.com/b099l3/FacebookImageShareIntent only dependency is the facebook sdk and it is contained in one activity.

Share image and text through Whatsapp or Facebook

Please try the below code and hopefully it will work.

    Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
whatsappIntent.setType("image/jpeg");
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}


Related Topics



Leave a reply



Submit