-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);
2
  • Photo got clicked successfully but Resutl of Activity returns 0 Commented Aug 6, 2023 at 0:22
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Aug 7, 2023 at 5:56

1 Answer 1

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)
 }
 }
answered Aug 6, 2023 at 5:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.