我想共享多个图像与单一标题在android.我正在使用下面的代码,但它与文本共享图像.文字在每个图像条目中都有复制.我只是想要一个图片列表,然后加上文字标题.请判断以下代码.

fun shareNotes(
    title: String,
    description: String,
    multiplePhotoPickerUri: List<Uri?>,
    navController: NavHostController,
    existingImages: MutableList<String>
) {
    val imageUriArray = ArrayList<Uri>()

    val shareIntent = Intent()

    shareIntent.action = Intent.ACTION_SEND_MULTIPLE

    shareIntent.setPackage("com.whatsapp")

    // Set the text content (title and description)

    val textContent = "$title\n$description"

    shareIntent.putExtra(Intent.EXTRA_TEXT, textContent)

    if (multiplePhotoPickerUri.isNotEmpty()) {

        multiplePhotoPickerUri.forEach { uri ->

            if(uri != null) {

                if(existingImages.contains(uri.path)) {

                    ImageUtils.createContentUriFromAppSpecificDirectory(
                        navController.context,
                        uri.path!!
                    )?.let {
                        imageUriArray.add(it)
                    }
                } else {
                    imageUriArray.add(uri)
                }
            }
        }
        shareIntent.putParcelableArrayListExtra(
            Intent.EXTRA_STREAM,
            imageUriArray
        )
        shareIntent.setType("image/jpeg")
    } else {
        // If no images are present, just set the type to text/plain
        shareIntent.type = "text/plain"
    }
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
    // Verify if WhatsApp is installed
    try {
        navController.context.startActivity(shareIntent)
    } catch (ex: ActivityNotFoundException) {
        Toast.makeText(navController.context, "Kindly install whatsapp first", Toast.LENGTH_SHORT).show()
    }
}

推荐答案

"共享"的确切行为没有得到很好的说明/记录.

接收应用程序如何处理共享数据由接收应用程序决定.在您的示例中,接收应用程序将文本元素作为标题应用到每个图像.但这完全取决于接收应用程序如何处理.

Stackoverflow上的几篇帖子表明不支持同时提供EXTRA_TEXT和EXTRA_STREAM.这似乎在很大程度上取决于接收应用程序的实现.

How can I sent multiple data types with Intent.ACTION_SEND_MULTIPLE when using a shareIntent?

Android相关问答推荐

编写视觉转型

如何在Android中使用TextView设置动态文本的样式

KMM项目生成错误-';在项目';中找不到测试类:共享';

fillMaxHeight中的分数在列内不起作用(android jetpack compose)

如何在Android Jetpack Compose中找到我的手机屏幕一行有多少个单词

Android Studio中的Kotlin版本不兼容错误:需要元数据1.9.0,但找到1.6.0

Jetpack Compose和Android Studio中的普通设计工具有什么不同?

如何删除Jetpack Compose中的Textfield底线

Jetpack Compose:带芯片的Textfield

需要 java 17 而不是 java 11:Android CI-CD GitHub Actions

在 kotlin 协同 routine 中,如何将数据范围限定为请求路径(以 MDC 为例)?

如何在 kotlin 中接收带有和不带有可空对象的集合并保持引用相同

如何禁用自动登录 google play games services android unity?

appcompat 依赖从何而来?

您如何衡量条形图的 4 个类别?

Compose `Icons.Outlined.Star` 没有概述

优化 Room 数据库迁移

Jetpack 组合和片段

在delphi中将Jnet_uri转换为Tbitmap

Google API:java.lang.ClassNotFoundException:找不到类sun.misc.Service