Unable to capture photos using the android camera intent

I am trying to capture an image using the android camera intent but it doesn’t work as expected.
I have a code that actually opens the camera but when I click on the capture icon it only makes a sound but nothing happens. Ideally, it’s supposed to show the image on the camera screen with 2 icons - to continue or to cancel - but it doesn’t show.
Find my code below:

private val takePicture =
        registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
            if (it.resultCode == RESULT_OK) {
                val imageBitmap: Bitmap = it.data?.extras?.get("data") as Bitmap
                binding.imageFirst.setImageBitmap(imageBitmap)
                Log.d("FirstFragment", "${it.data?.extras?.get("data")}")
            }
        }

binding.buttonCamera.setOnClickListener {
            val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
            takePicture.launch(cameraIntent)
        }

It turns out the callback isn’t even called.
I tried using the deprecated startActivityForResult() method but I still experienced the same thing. I’ve tried this on other devices and it works as expected.
The screenshot below shows the state of the screen whenever I take a photo, nothing changes.

Phone model name: Galaxy A53 5G
Phone model number: SM-A536E/DS

Thank you.

As far as I know you have done it wrong I have managed to get it working, so look on stackoverflow, and try it should work. Just look on Google how to take photos android coding or something like that.

Thanks for your response, @willshaw265.
I’ve checked on stackoverflow and other sites but nothing seemed to help. I followed the documentation exactly the way it was described but all to no avail.
If you’ve managed to get it work, can you share your solution with me?

Here’s code here I used it works,

for Mainactivity Java:

private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
private static final int MY_CAMERA_PERMISSION_CODE = 100;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
            {
                requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_PERMISSION_CODE);
            }
            else
            {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST);
            }
        }
    });
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }>

here’s code for layout file

<?xml version="1.0" encoding="utf-8"?>



and here’s code for manifest use only this permission, nothing else in file,

<uses-permission android:name="android.permission.CAMERA"/> 

done that simple

below is code for layout file
activity main.txt (491 Bytes)