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);
Asked
Active
Viewed 25 times
-1

toyota Supra
- 3,181
- 4
- 15
- 19
-
Photo got clicked successfully but Resutl of Activity returns 0 – DeGM Narmadapuram Aug 06 '23 at 00: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. – Community Aug 07 '23 at 05:56
1 Answers
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)
}
}

chetan vaghela
- 31
- 5