最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How can I get image from gallery and place it in edittext with html? - Stack Overflow

programmeradmin3浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论