That's what I tried to do:
private fun addImage(camera: Boolean = false) {
if (camera) {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(intent, CONST.CAMERA_REQUEST)
}
else {
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
startActivityForResult(intent, CONST.GALLERY_REQUEST)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK && data != null) {
if (requestCode == CONST.GALLERY_REQUEST) {
val selectedImage = data.data!!
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
val cursor = contentResolver.query(
selectedImage,
filePathColumn, null, null, null
)
cursor!!.moveToFirst()
val columnIndex = cursor.getColumnIndex(filePathColumn[0])
val picturePath = cursor.getString(columnIndex)
cursor.close()
val image = "<img src='file://$picturePath'>"
binding.edText.text?.insert(
binding.edText.selectionStart, HtmlCompat.fromHtml(image, HtmlCompat.FROM_HTML_MODE_LEGACY)
)
}
else if (requestCode == CONST.CAMERA_REQUEST) {
val photo = data.data
}
}
}
But as a result, I see only a symbol of the image, but not the image. I think that the problem may be in the path or in fromHtml.
I can place the image in imageView and it works, bot not in html.
As if something is missing