如何从服务要素表中获取ArcGis要素以执行添加附件。
我尝试了这个示例,并在其基础上使用了不同的功能层。 https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/tree/main/edit-feature-attachments
我记录了一些消息,例如图像大小、名称以及添加操作是否完成,但当我检查上传的附件时却没有。我也检查了文档,但没有找到任何有帮助的示例或书面代码。它缺乏那个部门
这是我尝试过的,尝试上传图像后检查第三张屏幕截图。
private fun addFeatureAttachment(selectedImageUri: Uri) {
// display a loading dialog
val dialog = createLoadingDialog("Adding feature attachment").also {
it.show()
}
// create an input stream at the selected URI
contentResolver.openInputStream(selectedImageUri)?.use { imageInputStream ->
// get the byte array of the image input stream
val imageBytes: ByteArray = imageInputStream.readBytes()
// create the attachment name with the current time
val attachmentName = "attachment_${System.currentTimeMillis()}.png"
Log.d("attachment","attachment_${System.currentTimeMillis()}.png")
lifecycleScope.launch {
selectedArcGISFeature?.let { arcGISFeature ->
// add the attachment to the selected feature
arcGISFeature.addAttachment(
name = attachmentName,
contentType = "image/png",
data = imageBytes
).onFailure {
return@launch showError(it.message.toString())
}
// update the feature changes in the loaded service feature table
serviceFeatureTable.updateFeature(arcGISFeature).getOrElse {
return@launch showError(it.message.toString())
}
}
applyServerEdits(dialog)
}
}
}
private suspend fun applyServerEdits(dialog: AlertDialog) {
// close the bottom sheet, as it will be created
// after service changes are made
bottomSheet?.dismiss()
// apply edits to the server
val updatedServerResult = serviceFeatureTable.applyEdits()
updatedServerResult.onSuccess { edits ->
dialog.dismiss()
// check that the feature table was successfully updated
if (edits.isEmpty()) {
showToast("not")
return showError(getString(R.string.failure_edit_results))
}
// if the edits were made successfully, create the bottom sheet to display new changes.
selectedArcGISFeature?.let { createBottomSheet(it) }
}.onFailure {
showError(it.message.toString())
dialog.dismiss()
}
}
fun selectAttachment() {
val mediaIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
activityResultLauncher.launch(mediaIntent)
}
```