I\'d like to share a photo with caption pre-filled from my app via a share intent, on facebook.
Example code
Intent intent = new Intent();
intent.set
As of 2017, facebook doesn't allow sharing of an image + text together, directly from your app.
Facebook will though, scrape a URL for title and image data and will use that in a share post.
As a workaround you could create a single page application* that dynamically loads the text/image you want to share (specified in the URL) and you can facebook-share that URL.
Notes:
0) add the latest facebook-sdk library to your build.gradle file
compile group: 'com.facebook.android', name: 'facebook-android-sdk', version: '4.25.0'
1) In your AndroidManifest.xml, add a meta-data tag within your <application>
section:
<application android:label="@string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
...
</application>
Add a facebook_app_id string (with your APP ID) to your strings.xml file:
<string name="facebook_app_id">12341234</string>
YOURFBAPPID is your Facebook App ID number found at https://developers.facebook.com/apps/
2) also add a <provider>
tag outside of your <application>
tag in AndroidManifest.xml
<provider android:authorities="com.facebook.app.FacebookContentProviderYOURFBAPPID"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
3) Create a ShareLinkContent object using their builder:
ShareLinkContent fbShare = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://yourdomain.com/your-title-here/someimagefilename"))
.build();
4) Share it from your fragment (or activity, etc.):
ShareDialog.show(getActivity(), fbShare);
https://developers.facebook.com/docs/android/getting-started