Instagram – Unter Android in Reels teilen

In diesem Dokument erfährst du, wie du das Teilen in deine Android-App integrierst, damit Nutzer*innen Bilder, Videos und Sticker in Reels auf Instagram teilen können.


Overview

Reels Layers

The Reels composer has a background video layer and an optional sticker layer.

  • Background Video Layer – A video fills the screen
  • Sticker Layer – An optional sticker can appear in front of the video

Sharing Icon

For a consistent user experience across apps, download the standard sharing icon for Instagram Reels and use it in your app.

Before You Start

You will need:
  • A Meta app ID
  • You must Go Live with your Meta app before your app users can share content

Terms and Policies

By accessing and using this functionality, you acknowledge and agree to be bound by the Meta Platform Terms and Developer Policies. You also represent and warrant that any content made available through your application or website, or shared to Instagram Reels from your application or website, does not infringe upon the intellectual property rights of any third party and that you own, control or have otherwise secured all rights necessary to distribute, copy, publicly perform and display, or otherwise use the content via this functionality, including as uploaded and shared on Instagram Reels. You further represent and warrant that you have the authority to make the foregoing representations on behalf of your organization. If you do not have such authority or are otherwise unable to make the foregoing representations, you are not authorized to continue and should not do so.

Teilen auf Instagram implementieren

Sie verwenden eine explizite Intention, um die Instagram-App zu starten und ihr Inhalte für Reels zu senden. Die Instagram-App empfängt den Inhalt, lädt ihn in den Reels-Composer und der*die Nutzer*in kann den Inhalt bearbeiten und in seinen*ihren Reels veröffentlichen.

Grundsätzlich bewirkt dein Teilen-Vorgang Folgendes:

  1. Es wird eine Intention instanziiert.
  2. Das Paket wird auf "com.instagram.android" festgelegt, um sicherzustellen, dass die Instagram-App die Intention verarbeitet.
  3. Deine Meta-App-ID und Medieninhalte werden an die Intention angehängt.
  4. Eine Aktivität wird instanziiert.
  5. URI-Berechtigungen werden gewährt, um sicherzustellen, dass Instagram den Medieninhalt lesen kann.
  6. Es wird bestätigt, dass die Aktivität die Intention auflösen und die Aktivität starten kann.

Entferne alle temporären Dateien, die du auf dem Gerät des*der Nutzer*in erstellst.

Daten

Sende beim Teilen in Reels folgende Daten.

DatenBeschreibung

Meta-App-ID

String

Erforderlich. Deine Meta-App-ID

Medien-Assets

String für ein einzelnes Asset

oder

eine Liste für mehrere Assets

Erforderlich. Eine der folgenden Optionen ist erforderlich:

  • Die URI für ein Bild, bei dem es sich um eine lokale Datei auf dem Gerät des*der Nutzer*in handelt. Unterstützte Bildformate:

    • JPG
    • PNG
  • Die URI für ein Video, bei dem es sich um eine lokale Datei auf dem Gerät des*der Nutzer*in handelt. Anforderungen an Videos:

    • 1080p (HD)
    • Dauer zwischen 3 und 60 Sekunden
    • Unterstützte Video-Formate sind H.264, H.265, MOV, MP4 und WebM
    • Die Abmessungen sollten dem Vollbildformat des Geräts entsprechen oder kleiner sein.
  • Eine Liste von URIs für Videos und/oder Bilder, bei denen es sich um lokale Dateien auf dem Gerät des*der Nutzer*in handelt.

Sticker-Asset

String

Die URI für einen Sticker, bei dem es sich um eine lokale Datei auf dem Gerät des*der Nutzer*in handelt. Unterstützte Sticker-Formate sind JPG und PNG. Empfohlene Abmessungen sind 640x480. Der Sticker wird über dem Video angezeigt.

Codebeispiele

Die folgenden Java- und Kotlin-Codebeispiele zeigen, wie du ein einzelnes Bild oder Video sendest, wie du mehrere Bilder oder Videos sendest und wie du Bilder oder Videos mit einem Sticker sendest.

Beispiel mit einer Mediendatei

Der folgende Beispielcode sendet eine Datei an Instagram, sodass der*die Nutzer*in sie bearbeiten und sie in seinen*ihren Instagram Reels veröffentlichen kann.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id"
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)

// Attach your image or video to the intent from a URI
val mediaAssetUri = Uri.parse("your-image-or-video-asset-uri-goes-here")
intent.setDataAndType(mediaAssetUri, "image/* video/*")
intent.putExtra(Intent.EXTRA_STREAM, mediaAssetUri)

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList = activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, mediaAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);

// Attach your image or video to the intent from a URI
Uri mediaAssetUri = Uri.parse("your-image-or-video-asset-uri-goes-here");
intent.setDataAndType(mediaAssetUri, "image/* video/*");
intent.putExtra(Intent.EXTRA_STREAM, mediaAssetUri);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    activity.grantUriPermission(packageName, mediaAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0);
}

Beispiel mit mehreren Mediendateien

Der folgende Beispielcode sendet mehrere Dateien an Instagram, sodass der*die Nutzer*in sie bearbeiten und sie in seinen*ihren Instagram Reels veröffentlichen kann.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL_MULTIPLE")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id"
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)
intent.setType("image/* video/*")

// Attach your files to the intent
val uri1 = Uri.parse("your-first-uri-goes-here")
val uri2 = Uri.parse("your-second-uri-goes-here")
val mediaList = mutableListOf<Uri>()
mediaList.addAll(listOf(uri1, uri2))
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(mediaList))

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList =
activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (uri in mediaList) {
  for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
  }
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL_MULTIPLE");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);
intent.setType("image/* video/*");

// Attach your files to the intent
Uri uri1 = Uri.parse("your-first-uri-goes-here");
Uri uri2 = Uri.parse("your-second-uri-goes-here");
ArrayList<Uri> mediaList = new ArrayList<>();
mediaList.add(uri1);
mediaList.add(uri2);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, mediaList);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (Uri uri : mediaList) {
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0);
}

Beispiel mit Sticker

Der folgende Beispielcode sendet ein Video an Instagram und enthält einen optionalen Sticker, damit der*die Nutzer*in es bearbeiten und in seinen*ihren Instagram Reels veröffentlichen kann.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id" 
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)

// Attach your video to the intent from a URI
val videoAssetUri = Uri.parse("your-video-asset-uri-goes-here")
intent.setDataAndType(videoAssetUri, "video/*")
intent.putExtra(Intent.EXTRA_STREAM, videoAssetUri)

// Attach your sticker to the intent from a URI
val stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here")
intent.putExtra("interactive_asset_uri", stickerAssetUri)

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList = activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, videoAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
    activity.grantUriPermission(packageName, stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);

// Attach your video to the intent from a URI
Uri videoAssetUri = Uri.parse("your-video-asset-uri-goes-here");
intent.setDataAndType(videoAssetUri, "video/*");
intent.putExtra(Intent.EXTRA_STREAM, videoAssetUri);

// Attach your sticker to the intent from a URI
Uri stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here");
intent.putExtra("interactive_asset_uri", stickerAssetUri);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    activity.grantUriPermission(packageName, videoAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    activity.grantUriPermission(packageName, stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0);
}

GitHub-Beispiel und Video-Tutorial

Meta hat zur Veranschaulichung Beispielcode für den Instagram-Teilvorgang in Reels auf GitHub unter fbsamples/share_to_reels_android veröffentlicht. Sieh dir das folgende Video an, um zu erfahren, wie du das GitHub-Beispiel verwendest.

Da ist leider was schiefgelaufen
Leider kann dieses Video nicht richtig abgespielt werden.