S
S
Stanislav Nekrasov2019-05-01 11:55:31
Android
Stanislav Nekrasov, 2019-05-01 11:55:31

Why doesn't the camera start via intent on Android 9.0?

I am making an android application. At the moment of pressing the button, I need to: open the camera so that the user takes a picture, and if everything went well, then send it to the server.
I write this code:

private void comeBtnClicked() {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0 && resultCode == RESULT_OK) {
            Bitmap image = (Bitmap) data.getExtras().get("data");
            Toast.makeText(This, image.toString(), Toast.LENGTH_LONG).show();
        }
    }

In AndroidManifest.xml I wrote this:
<uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />

(The first line can probably be removed?)
On two devices with Android 4.4.2 (API 19), everything starts. (I'm testing through real devices, since the emulator does not work..)
On a Samsung Galaxy A6+ 2018 (Android 9.0 API 28) device, the camera does not want to start. The first time the application simply restarts, the second time the error "The application {name} failed again" is displayed.
So, questions:
1) How to make everything work fine, on all devices (with a camera)?
2) Is it possible to somehow launch the camera through Intent so that it immediately shoots from the front camera?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Developer, 2019-05-01
@Metalofon

Where is the permission check?
Starting from the 6th version, this is a mandatory requirement in Android.
It is necessary to check whether the rights to the camera are given and if not, then request the rights (show the window), get the result, process it and take the photo again.
If you look at the logs, you will see an error.
She will be about it.
Please send error logs next time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question