-1
Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File file = new File(Environment.getExternalStorageDirectory(), "MyPhoto.jpg");
            Uri uri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", file);
            m_intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(m_intent, CAMERA_REQUEST);
toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

0

DeGM Narmadapuram, Here I am sharing full code for clicking image from Camera and show it to imageview.


try {
                val chooserIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
                captureFile = createImageFile(this@TIDProcessActivity)

                if (captureFile != null) {

                    val photoURI = FileProvider.getUriForFile(
                        this@TIDProcessActivity,
                        "com.abcdemo.fileprovider",
                        captureFile
                    )

                    chooserIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
                }
                startActivityIntent.launch(chooserIntent)
            } catch (e: Exception) {
                Log.e("TAG", "onCreate: " + e.message)
            }

From this method you can capture picture and that picture has URI already created while clicking image so when you get result you can directly show image from this URI like below :


var startActivityIntent = registerForActivityResult<Intent, ActivityResult>(
        ActivityResultContracts.StartActivityForResult()
    ) {
        
        val bitmap = BitmapFactory.decodeFile(captureFile.absolutePath)
        if (bitmap != null) {
            val fileName = System.currentTimeMillis().toString()
            Glide.with(this).load(bitmap).into(binding.zeroTokenImagePath)
        }

    }