本文件說明如何將分享功能整合至 Android 應用程式,方便用戶將圖像、影片和貼圖分享到 Instagram 的 Reels。
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.
您可以使用 Explicit Intent(顯示意圖)啟動 Instagram 應用程式並向其傳送 Reels 內容。Instagram 應用程式將接收內容並載入到 Reels 撰寫工具,用戶即可編輯內容並發佈到自己的 Reels。
分享流程通常會執行以下操作:
"com.instagram.android"
,確保 Instagram 應用程式處理 Intent。請移除您在用戶裝置上建立的任何暫存檔案。
分享到 Reels 時,應傳送下列資料。
資料 | 說明 |
---|---|
Meta 應用程式編號 字串 | 必要項目。您的 Meta 應用程式編號 |
影音素材 單一素材為字串或 多個素材為清單 | 必要項目。您需要以下其中一個選項:
|
貼圖素材 字串 | 貼圖的 URI,該貼圖為用戶裝置上的本機檔案。可接受的貼圖格式為 |
下列 Java 和 Kotlin 程式碼範例說明如何傳送單一圖像或影片、如何傳送多個圖像或影片,以及如何傳送包含貼圖的圖像或影片。
下列程式碼範例傳送單一檔案至 Instagram,方便用戶編輯並發佈到自己的 Instagram Reels。
// 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)
}
下列程式碼範例傳送多個檔案至 Instagram,方便用戶編輯並發佈到自己的 Instagram Reels。
// 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)
}
下列程式碼範例傳送影片至 Instagram 並包含一個選用的貼圖,方便用戶編輯並發佈到自己的 Instagram Reels。
// 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 已在 GitHub 上發佈 Instagram 分享到 Reels 的範例程式碼,網址為:fbsamples/share_to_reels_android。請觀看下列影片,瞭解如何使用 GitHub 範例。