我想共享多个图像与单一标题在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()
}
}