Berbagi ke Reels Instagram Dari Android

Dokumen ini menunjukkan kepada Anda cara mengintegrasikan proses berbagi ke dalam aplikasi Android Anda, sehingga pengguna dapat berbagi gambar, video, dan stiker ke Reels di Instagram.

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.

Terapkan Berbagi ke Instagram

Anda menggunakan Niat Eksplisit untuk meluncurkan aplikasi Instagram dan mengirimkan konten untuk Reels. Aplikasi Instagram menerima konten, memuatnya ke komposer Reels, dan pengguna dapat mengedit dan memublikasikan konten ke Reels mereka.

Secara umum, alur berbagi Anda melakukan hal berikut:

  1. Instansiasi niat.
  2. Mengatur paket sama dengan "com.instagram.android" untuk memastikan bahwa aplikasi Instagram menangani niat tersebut.
  3. Melampirkan ID Aplikasi Meta dan konten media Anda ke niat tersebut.
  4. Instansiasi aktivitas.
  5. Memberikan izin URI untuk memastikan Instagram dapat membaca konten media.
  6. Memverifikasi bahwa aktivitas dapat menyelesaikan niat dan memulai aktivitas.

Hapus semua file sementara yang Anda buat di perangkat pengguna.

Data

Anda harus mengirimkan data berikut saat Anda berbagi ke Reels.

DataDeskripsi

ID Aplikasi Meta

string

Wajib. ID aplikasi Meta Anda

Aset Media

string untuk satu aset

atau

daftar untuk beberapa aset

Wajib. Salah satu opsi berikut wajib ada:

  • URI untuk gambar yang merupakan file lokal di perangkat pengguna. Format gambar yang dapat diterima:

    • JPG
    • PNG
  • URI untuk video yang merupakan file lokal di perangkat pengguna. Video harus:

    • 1080p
    • durasi antara 3 dan 60 detik
    • format video yang diterima H.264, H.265, MOV, MP4, dan WebM
    • dimensi harus layar penuh perangkat atau lebih kecil
  • Daftar URI untuk video dan/atau gambar yang merupakan file lokal di perangkat pengguna.

Aset Stiker

string

URI untuk stiker yang merupakan file lokal di perangkat pengguna. Format stiker yang dapat diterima adalah JPG dan PNG, dan dimensi yang direkomendasikan adalah 640 x 480. Stiker muncul di video.

Contoh Kode

Contoh kode Java dan Kotlin berikut menunjukkan cara mengirim satu gambar atau video, cara mengirim banyak gambar atau video, dan cara mengirim gambar atau video dengan stiker.

Contoh dengan Satu File Media

Contoh kode berikut mengirimkan file ke Instagram, sehingga pengguna dapat mengedit dan memublikasikannya ke Instagram Reels mereka.

// 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);
}

Contoh dengan Banyak File Media

Contoh kode berikut mengirimkan banyak file ke Instagram, sehingga pengguna dapat mengedit dan memublikasikannya ke Instagram Reels mereka.

// 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);
}

Contoh dengan Stiker

Contoh kode berikut mengirimkan video ke Instagram dan menyertakan stiker opsional, sehingga pengguna dapat mengedit dan memublikasikannya ke Instagram Reels mereka.

// 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);
}

Contoh GitHub dan Tutorial Video

Untuk memudahkan developer, Meta telah menerbitkan kode contoh untuk Berbagi ke Reels Instagram di GitHub di fbsamples/share_to_reels_android. Tonton video berikut untuk mempelajari cara menggunakan Contoh GitHub.

Ada Masalah
Kami mengalami masalah saat memutar video ini.