Why not start the camera via intent on Android 9.0?

I am doing app on Android. At the moment of pressing the button I need to open the camera to take a picture, and if all goes well, then send it to the server.
Write such 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 ordered this:
<uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />

(The first line probably can be removed?)
On two devices with Android 4.4.2 (API 19) all started. (Test using real device as emulator does not work..)
On your Samsung Galaxy device A6+ 2018 (9.0 Android API 28) the camera doesn't want to run. The first time just restarts the app, the second time an error is displayed "the app {name} is again a failure has occurred".
So, questions:
1) How to make so that all worked fine, on all devices (with camera)?
2) is there any way using Intent to start the camera so that it immediately took off with the front camera?
March 20th 20 at 11:21
1 answer
March 20th 20 at 11:23
Solution
Where check permissions?
Since the 6-th version this is a mandatory requirement in Android.
It is necessary to check whether the rights to the camera and if not given, request the law (show a window), get the result, process it and retake the photo.

If you look at the logs, you will see the error.
It will be exactly that.

Next time send logs with errors
It is not parmisano. They then do not need them from the manifest you want to delete. - Mandy_Swaniaws commented on March 20th 20 at 11:29
@Jeanne_Kli, okay?!! Without permisison camera not include - Tommie20 commented on March 20th 20 at 11:32
Okay I will Try to put a check, if you help, we'll make a decision. - carleton.Connelly commented on March 20th 20 at 11:26
@Amara_Ledner5, the app itself does not use the camera, it launches another app via intent. For this parmesani not needed. - Mandy_Swaniaws commented on March 20th 20 at 11:35
@Amara_Ledner5, Thanks, it worked... - carleton.Connelly commented on March 20th 20 at 11:38
@Jeanne_Kli, I also thought that is not necessary, but it turned out that permissions needed) - carleton.Connelly commented on March 20th 20 at 11:41
@hillary24, @Amara_Ledner5, and yet not. Parmesani camera there is not exactly need. The problem was clearly something else, and it looks like she did it indirectly. The prescription of parmesano in the manifest and especially request them in ratite - extra steps.

Here sketched a simple example where everything works on all versions of Android:
manifest
layout
activity

The project

So, I advise you to figure out what was the problem actually. - Mandy_Swaniaws commented on March 20th 20 at 11:44
@Jeanne_Kli, Damn It. So write-write, read docks uglovye that without permisison nowhere, and then BAM! there they change something and break and then head...
Thanks, good example. - Tommie20 commented on March 20th 20 at 11:47

Find more questions by tags Android