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.
Reels LayersThe Reels composer has a background video layer and an optional sticker layer.
Sharing Icon
|
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:
"com.instagram.android" festgelegt, um sicherzustellen, dass die Instagram-App die Intention verarbeitet.Entferne alle temporären Dateien, die du auf dem Gerät des*der Nutzer*in erstellst.
Sende beim Teilen in Reels folgende Daten.
| Daten | Beschreibung |
|---|---|
Meta-App-ID String | Erforderlich. Deine Meta-App-ID |
Medien-Assets String für ein einzelnes Assetoder eine Liste für mehrere Assets | Erforderlich. Eine der folgenden Optionen ist erforderlich:
|
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 |
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.
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)
}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)
}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)
}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.