Sharing to Stories for Android Developers

As an Android developer, you can implement Sharing to Stories by using implicit intents or the Facebook SDK for Android.

Implicit Intents

To implement Sharing to Stories using implicit intents, in general, your sharing flow should:

  1. Instantiate an implicit intent with the content you want to pass to the Facebook app.
  2. Start an activity and check that it can resolve the implicit intent.
  3. Resolve the activity if it is able to.

You can pass the following content to the Facebook app:

ContentTypeDescription

Facebook app ID *

String

(Required) Your Facebook app ID.

Background asset *

Uri

Uri to an image (JPG, PNG) or video (H.264, H.265, WebM). Recommended image dimensions: device fullscreen or smaller. Recommended ratio: 9:16. Videos can be 1080p and up to 20 seconds in duration. The Uri needs to be a content Uri to a local file on device.

Sticker asset *

Uri

Uri to an image (JPG, PNG). Recommended dimensions: 640x480. This image will be placed as a sticker over the background. The Uri needs to be a content Uri to a local file on device.

Background layer top color

String

A hex string color value used in conjunction with the background layer bottom color value. If both values are the same, the background layer will be a solid color. If they differ, they will be used to generate a gradient instead. Note that if you are passing a background asset, the asset will be used and these values will be ignored.

Background layer bottom color

String

A hex string color value used in conjunction with the background layer top color value. If both values are the same, the background layer will be a solid color. If they differ, they will be used to generate a gradient instead. Note that if you are passing a background asset, the asset will be used and these values will be ignored.

* In addition to your app's FB app ID, you must pass the Facebook app a background asset (image or video), a sticker asset, or both.

Sharing an Image or Video Background Asset

This sample code shows how to pass the Facebook app a background layer image or video asset. Note that both the Data and Type must be set for the Intent.

// Define photo or video asset URI
Uri backgroundAssetUri = Uri.parse("your-image-asset-uri-goes-here");
String appId = "1234567"; // This is your application's FB ID

// Instantiate implicit intent with ADD_TO_STORY action
Intent intent = new Intent("com.facebook.stories.ADD_TO_STORY");
intent.setDataAndType(backgroundAssetUri, "image/jpeg");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("com.facebook.platform.extra.APPLICATION_ID", appId);

// Instantiate activity and verify it will resolve implicit intent
Activity activity = getActivity();
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0);
}

Sharing a Sticker Asset

This sample code shows how to pass the Facebook app a sticker layer image asset and a set of background layer colors. Note that if you do not supply background layer colors, we will set the background layer color to #222222.

// Define photo or video asset URI
Uri stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here");
String appId = "1234567"; // This is your application's FB ID

// Instantiate implicit intent with ADD_TO_STORY action,
// sticker asset and background colors
Intent intent = new Intent("com.facebook.stories.ADD_TO_STORY");
intent.setType("image/jpeg");
intent.putExtra("com.facebook.platform.extra.APPLICATION_ID", appId);
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.putExtra("top_background_color", "#33FF33");
intent.putExtra("bottom_background_color", "#FF00FF");

// Instantiate activity and verify it will resolve implicit intent
Activity activity = getActivity();
activity.grantUriPermission(
    "com.facebook.katana", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0);
}

Facebook SDK for Android

To implement Sharing to Stories by using the Facebook SDK for Android, in general, you should:

  • Model the content that will be shared — for images, construct a SharePhoto; for videos, construct a ShareVideo.
  • Add the modeled content to ShareStoryContent.

You can pass the following content to the Facebook app:

ContentTypeDescription

Background asset *

Uri

Uri to an image (JPG, PNG) or video (H.264, H.265, WebM). Recommended image dimensions: device fullscreen or smaller. Videos can be 1080p and up to 20 seconds in duration. The Uri needs to be a content Uri to a local file on device.

Sticker asset *

Uri

Uri to an image (JPG, PNG). Recommended dimensions: 640x480. This image will be placed as a sticker over the background. The Uri needs to be a content Uri to a local file on device.

Background color list *

List

A list of hex string color values used to generate a gradient from top to bottom, in the order in which they appear in the list. Note that if you are passing a background asset, the asset will be used and the color list will be ignored.

* You must pass the Facebook app a background asset, a sticker asset, or a list of background colors.

Sharing a Bitmap Image Background Asset

This sample code shows how to pass the Facebook app a bitmap image background asset.

// Model an image background asset
Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .build();

// Add to ShareStoryContent
ShareStoryContent content = new ShareStoryContent.Builder()
        .setBackgroundAsset(photo)
        .build();

Sharing an Image Background Asset with a URI

This sample code shows how to pass the Facebook app a background asset from an image uri.

// Model an image background asset
Uri imageUri = Uri.parse("your-image-uri");
SharePhoto photo = new SharePhoto.Builder().setImageUrl(uri).build();

// Add to ShareStoryContent
ShareStoryContent content = new ShareStoryContent.Builder()
        .setBackgroundAsset(photo)
        .build();

Sharing a Video Background Asset

This sample code shows how to pass the Facebook app a video background asset.

// Model a video background asset
Uri videoUri = Uri.parse("your-video-uri");
ShareVideo video  = new ShareVideo.Builder().setLocalUrl(videoUri).build();

// Add to ShareStoryContent
ShareStoryContent content = new ShareStoryContent.Builder()
        .setBackgroundAsset(video)
        .build();

Sharing a Background Color

This sample code shows how to pass the Facebook app an image sticker asset, and a list of background colors to be rendered from top to bottom.

// Model an image sticker asset
Uri imageUri = Uri.parse("your-image-uri");
SharePhoto photo = new SharePhoto.Builder().setImageUrl(uri).build();

// Define color list
List<String> backgroundColorList = Arrays.asList("#33FF33", "#FF00FF", "#33FF33", "#FF00FF");

// Add to ShareStoryContent
ShareStoryContent content = new ShareStoryContent.Builder()
        .setStickerAsset(photo)
        .setBackgroundColorList(backgroundColorList)
        .build();