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.
Reels LayersThe Reels composer has a background video layer and an optional sticker layer.
Sharing Icon
|
You will need:
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.
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:
"com.instagram.android"
untuk memastikan bahwa aplikasi Instagram menangani niat tersebut.Hapus semua file sementara yang Anda buat di perangkat pengguna.
Anda harus mengirimkan data berikut saat Anda berbagi ke Reels.
Data | Deskripsi |
---|---|
ID Aplikasi Meta string | Wajib. ID aplikasi Meta Anda |
Aset Media string untuk satu asetatau daftar untuk beberapa aset | Wajib. Salah satu opsi berikut wajib ada:
|
Aset Stiker string | URI untuk stiker yang merupakan file lokal di perangkat pengguna. Format stiker yang dapat diterima adalah |
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 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)
}
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)
}
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)
}
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.