Welcome back.
In this video, we are going to add the functionality to take the photo from the camera and put that
into our view.
And in order to do so, I'm going to create a new method.
As you can see, we have this choose from gallery and now you can take the photo from camera.
So private fun, take a photo from camera would be a good name, I think.
And then we are going to pretty much do the same thing as we've done here, except that we ask for different
permissions and we do slightly different things.
So we can just copy the whole code from our choose photo from gallery.
And then instead of just having the written right external storage permissions, we are also going to
ask for the permission to use the camera.
So camera.
And in here we have the listener with multiple permissions and on permissions checked.
I want to start an intent as well, but this time the intent will not be action pic, but the intent
will be with the media store directly so intense.
Media store DOT action image capture.
All right, and then start activity for yourself.
Well, here I need a different name and I'm going to use camera.
Of course, we still need to create this.
So let's go ahead and create a new private, considerable private concert file camera.
And I'm going to set that value to gallery was one, camera two.
Then, of course, we had this one point where we had the selection of the two options, right, so
you could choose either photo from gallery or for now, what we did is we had this toast make text where
we said camera selection coming soon.
Well, the sun is exact now.
So here we can go ahead and call our take photo from camera method.
And then, of course, in our activity for result or on activity result, to be precise, that's where
we had the request called gallery and that's what we did in there.
And now we need to do something similar when we have the request code, camera.
So else if request code.
Is camera.
And here's the camera like this.
Then we want to run some code and me, we need to make sure that we are on the same level.
Yes, we are.
All right.
And then and here I will need to create another bitmap, so.
I'm just going to use this or call this one thumbnail, which will be of type bitmap, and it takes
the extras from our bitmap.
And there we get that as data.
OK, so this is something that we have not done yet and we also need to import bitmap here in order
to use this.
But generally what we're doing is we take this data.
So here we had data and actually let me see.
Yeah, it's a nullable, so it's OK to use the double exclamation marks here and we get extras from
it.
So when you take an image, the data will contain the image, of course, and we get that data by using
to get and then the name of the data.
And in this case, the data is called data.
And we transferred that or we convert that into a bitmap.
So the data that we get from the camera, we can get that by using this approach or the bitmap data,
so to speak.
All right.
And it is off type bitmap internally.
Of course, it's going to be of another type.
It's going to be of type intent, as we can see.
So data is of type intent.
And then this kit will give us an object.
So we need to pass on a string key.
So it could be anything.
Right.
But we know that it's of type bitmap because it's an image that we're using here or that we are taking
with the camera.
That's why we can then go ahead and use that.
And now, of course, we can do the same thing as we've done here where we say I've placed image that
image bitmap.
OK, so we did that before with the gallery, but this time we're doing it with our bitmap that we just
created, which is our thumbnail that is based on the image that we get from the camera.
All right, and at this point, we can test this in order to select an image from the camera.
We are so let's add the image, let's select capture captured photo from camera, so this is the intent
that we start and then let's take another angle here.
Hold the old key.
So I'm taking a picture of the sofa.
All right, let's select that.
And we are.
All right, so very similar code, slight differences, of course, but basically that's already it.
So now you can select images and put them into your image views from the camera.
Already, I'd say, see you in the next video.