Let's go ahead and create a listener for this PTEN take the picture Potten so I can say PTEN take a
picture that said unclick listener Pythian that take a picture.
That's what I collect listener and now I need to pass the context so I can just pass an activity that
is.
So the main activity that this is going to be actually a listener when the user interacts with is spartan.
So in order for this main activity class to be the listener in order to be notified whenever they use
that interacts with this PTEN taking part in this class must implement their unclick listener interface.
So you're already familiar with that right.
So I just need to scroll to the top and here it says main activity extends app compacter activity.
And here I can say space implements view dot and click click center.
So the idea that this class is actually implementing this view that unclick this in an interface this
class must provide an implementation for the unclick my foot.
So let's scroll down here.
And after the end in curly brace of this uncreate method and before the end and curly brace of this
main activity class I had just been unclick and that person interchange keyboard.
So now we are all we're writing this.
Unclear if an insider view that unclick the center interface.
So whenever that is that actually interacts with the SBT and take a picture.
But in this Smurfette here unclick is going to be called.
Right.
But because we have two buttons inside our application we have the first one BTA take a picture and
the second one is PTEN save the picture.
So let's also create a listener for this SBT and save the picture.
So after this line of code that sets the listener for the spit take a picture or can just say PTEN safety
feature that sits unclick listener.
And here again I can just pass the context meant I think that that is so now because this class is actually
conforming to this view that unclick us in an interface.
And if you are providing MF Smurfit inside that interface here.
So whenever they use it actually interacts with these two buttons into hip or Pythian save the picture
this if it is going to be called.
So you're already familiar with that.
Right.
So how we can actually differentiate between these two buttons.
By using this view here it is you object that I to receive as an argument from the Songkhla if I can
say this uncle if I can say if this is actually the name of this argument I can change the name of this
argument to view.
It's better to name it view.
So if view that ID so let's actually get just a bit here.
ID is equal to or data ID but Pythian take a picture then in that case here we are a hundred and fifty
percent sure that is pretty and take a picture is actually clicked.
So inside this statement you can actually put the logic that we want to be executed Whenever to use
that interacts with this and take a picture so I can create an ELSE IF statement here.
So after the head curly brace of this if statement I can say Elsy else if inside the apprentice's I
can say view that get Id get ID right and then put an equal operator here Aard thought id that Pythian
save the picture here and here you are 100 I'm 50 percent sure that this beauty and save the picture
is actually clicked.
So it is going to ask you this if statement.
So how this is how we can actually differentiate between Actually these buttons.
So let's go inside the curly braces of this statement.
If you view that it is R that R D that BT and take a picture.
Now I can say so here because we want to actually get the user's permission in order to access the camera.
It is very important.
It is a must actually.
To ask the user in order to get the permission to access the camera.
So we must actually ask the user for that.
So just type in here in it and the name of this variable is going to be permeation result permission
resolved.
Assignment operator context compact context compact that a check self permission.
So here first we need to pass the context which is going to be main activity that this comma.
And for the second argument we need to say manifest such as they've been here manifest that permission
DOT camera.
So we want to ask the user to give us the permission to access the camera.
So we need to also put this permission inside the manifest file.
Let's actually open the address structure here at the top and you just click on View and then tool windows
and then click on project here.
This is our Android view right.
So you can see this inside this app folder we have this manifests.
So just double click on it.
And here if you open this for the audience it is our manifest that is him on file.
So inside this manifest.
Hi.
OK.
Before this application here and inside its manifest manifest.
Let me actually just double click on this tab in order to make this area either just open a tag and
just type in here user's permission.
So the permission is going to be camera.
Right.
So just they've been here and read the permission of the camera.
And then just sell clothes this tag by using this slash and this and tag here.
So now you are actually putting this permission here let's go to them in the class.
So here we are checking for that condition for that permission.
We are taking that if the permission is actually given to us by the user.
Then the result is going to be actually assigned to this valuable permission or as a result.
So let's create an if statement here.
After this line of code after this valuable so I can say if permission result is equal to package manager
that permission granted I can just open and close this statement by using these curly braces.
Now I can say that the user has given us to access the camera so it is possible to actually access the
camera right but we need to actually check for another condition.
What if the user doesn't have the camera.
What if the user's device doesn't have a camera.
So for that case you also must create an if statement in order to check for that specific condition.
So this if statement is checking for their permission granted.
Right.
So what happens if the user doesn't allow us to actually access the camera.
In that case we want to actually ask the user to give us the permission to access the camera.
So after this if statement after the end curly brace of this if statement if statement I can't say as
I don't like could open and close this statement by using these curly braces so that I can actually
request that I can say Let me just paste this line of quote here so you can see activity compact that
requires the permissions.
So first we need to pass the context which is going to be main activity that this and for the second
argument we need to pass an ad a string values that actually holds the permissions that we want to actually
ask the user.
So we want to use user only allow us to access the cameras so we have only an outrage.
So News Stream at 8:00 that this audio only has one value.
Right.
So instead of Colibri inside the curly braces you can see that we have this permanent manifest that
we're in that camera.
And for the second argument you can see it is actually this request the court.
So this request card is used for actually requesting their permission.
So it is one case it doesn't really matter what you put here but it must be a unique value a unique
number.
So what is ok here.
So let's go inside this statement.
So if they use that actually has given us the permission to access the camera I can't say.
So first of all we need to access the package manager so I can't say enough.
So here I am.
First of all let's create a body.
But of the package manager or package manager package manager assignment operator gets package manager
semicolon.
Right.
So in this way we are actually accessing the package manager of the application that has the specific
features of the device.
For example if the user has a camera or not this package manager can have those values those data.
And now I can say if package manager DOT has system feature package manager with capital P write package
manager that Tamarod package manager that feature other like camera then open and close open and close
this if statement by using the curly braces so this means if the device if the package manager that
has system feature package manager that feature tramadol.
If that device has actually a camera and B can access that camera right.
If the camera is working properly and we can access it now I can say we need to create an intent for
the camera.
So here I can say intent and the name of this entity is going to be camera intent assignment operator
new new intent an inside Apprentice's I can't say Medhi us or that action image capture because we want
to actually allow the user to access the camera and take a picture.
We want this intense media store that actual image capture we are creating an instant specific for that.
So let's put a semicolon here.
So it's going to access the camera application right.
And here I can say start activity for result.
So because we want to get that image that is actually captured by the user by using the camera we need
to use this method start activity for result.
So as you can see this and if it needs two arguments the first one is the intent.
So if you have the intent the camera intent come up the next argument is going to be that requires the
court which is very important because by using this request code you are accessing the camera.
Right.
And we're getting that picture.
And later when we want to get that picture and put it on our image view we must use that request court
in order to identify that image.
This is very important.
So let's provide and our request let's actually scroll to the top.
And inside this class after declaring these variables I can actually say a private or private static
final INT and here I can say let's actually capitalize it like this is actually our constant.
So it's a convention in dhaba to capitalize are constant names.
So I can't say camera camera underly image underline request request code underline quote.
Right.
Assignment operator let's assign a unique value.
This is very important.
We must assign a unique value a unique integer value to this constant.
So 1000 is unique here right.
Let's scroll down here and now for the second argument of the Smurfette I can say camera image request
the.
That's it.
So now that we have this statements so it is this statement says if the device has a camera or not.
If this device has a camera then it's going to actually create an intent for the camera.
It's going to actually allow the user to access the camera application and take a picture.
And then if you have the Smurfette in order to open the activity the camera activity actually the camera
intent and the and we pass this request card right.
So what happens if the user if the user's device doesn't have a camera.
We need to check for that condition too.
So after the end increase the price of this statement I can actually create an ill statement so as that
I just need to open and close this statement by using these curly braces.
And here I can say toast does make text first we need to pass the context my activity that this comma.
And for the sake of argument we need to pass the value that you want to show to the use that and here
I can see your device.
Does not have a camera does not have a camera write and here I just need to put a comma and then I just
need to specify the duration of the message that I want to show to the.
So it is going to be lenth short.
And then that show.
So you're already familiar with the syntax of actually showing a toast to the user.
So now that we have these quotes here let's run the application and let's see what happens.
Let me actually run the application now.
So here you can see that our application is running.
Right.
And I'm going to get you to click on this.
Take a picture button let's click on it.
Now as you can see it's going I should ask their permission is going to ask us that this application
is going to access the camera do you want to allow this app to access the camera.
So here if I click on it now it's going to allow me to access the camera but I just need to click on
it again take a picture.
Now you can see that the camera app is actually open.
And we can access the camera of the application.
So we created an instant for this camera here.
Right.
And we call it the Start activity for results so it's going to open this activity for us and we passed
the camera intent.
And this is our request that we're going to use it later.
Well we want to get this picture.
So for example this is actually emulated right is not the real camera.
This is actually an emulated terminal.
So let's actually take the picture here.
So another picture is taken.
Now if I click on this.
I can hear in order to actually accept this image you can see that nothing happened right.
All you want that takes an image to appear here in place of this image inside this image.
Because image view is a shell that holds the actual image.
So you want this image you now hold that image that I have taken by using that camera.
So how we can do that we need to overwrite this thot activity for results.
And we need to actually provide an implementation for this method.
So now let's actually scroll down here and you can see that we have these curly braces that are related
to the cleanup effort.
So after the curly brace of this method and before the end in curly brace of this main activity class
I'm going to just step in here on activity resolved just typing here on activity and the autocomplete
feature of Android studio is going to help you to just dismiss it on activity results or just a person
until Chanute keyboard.
So you can see this if it is actually protected.
Protected means that only the subclasses of that of the activity class can actually use this method.
So our main activity class is a subclass of activity.
Right.
So we can actually override this method on activity result we can see these arguments.
Request code which I talk to you we talked about it previously in this story.
We have the result code and we have the data.
So now it is actually calling to support that an activity result here.
This method is must be called after this line of code.
Here I can say if we have this request code right so here I can see if request code is actually the
same as the request code that was sent to the camera or intent here like camera image request code.
So here I can say if request call is a call to camera with tropicals see camera image request code right.
And we have this result here we want to check that if the intent is actually opened normally and we
have no problems.
So here I can just type in results code.
This is very important that you refer to this result called another request card.
OK.
Is equal to result.
OK.
So here we are checking that everything is fine and nothing goes wrong here.
Right.
Let's go inside the curly curly braces of this statement.
OK.
And here first of all we need to get the bundle right.
So bundle is going to be actually given to us by the state.
You can see this data because of the intent.
We received this data from an activity result.
Right.
So first of all let me tell you that when this activity resolved if it is going to be caught.
So after this superdad and on activity result you're going to create a toast message.
So here I can say toast that makes text first I need to pass the context which is going to be main activity
that this write come up and really to pass the message so the message is going to be an activity a result
on activity result.
Is called right is called and I put a comma here and then I need to specify that actually the duration
so length short that show.
So let's run the application because I want to show you then decide if it is called Ventas an activity
result is actually caught.
Let me show you the emulator.
So not our application is running on the simulator right.
Let's click on take a picture.
Let's take a picture now.
And this really can accept as you can see it says unactivated result is called.
So the unexpected result is called When we take a picture and we actually accept that.
Now we can see that here when we back to this main activity here an activity result is called.
So here is the place this non-activity result is actually is the place where we want to actually put
that image that is taken by the user by using the camera of the device and put that image here inside
this image view.
So let's go back to our I should imagine if the glass inside is an activity result.
So now we have this statement inside this if statement is the place to get that picture how we can get
that picture.
First we need to create of the level of the bundle.
So bundle the name of our idea but it's going to be bundled assignment operator.
So we have these data arguments right which is the intent.
The intent is the intent of the camera intent actually right.
So I can't say data that gets X through us semi-colon.
So by using this to get extra Smurfette on this data which is of type intent you are going to access
the data that is inside that intent to actually image.
Right.
So this intent which is its name is data right.
These data holds that image that is taken by the user by calling this a good extra Asmaa if it does
get stressed if it is going to return a bundle the return type of this method his bundle.
And we can't assign the return type of this value that returns value of the Smurfette to this variable
bundle.
Let me show you the Android documentation.
So here it is the android documentation right.
And I actually searched for the intense class list inside the first part the sense for Internet and
that app that intent on Android that content that the Internet actually.
Right.
So just like this one here and here let's search for the get extra effort.
So in order to search for a specific Meffert in Andhra it's documentation if you are using a match point
six you just need to hold down to the comments on your keyboard and the person that that key on your
keyboard.
And then just search for that specific method.
If you are using of Indos machine you just need to hold down the control on your keyboard and then press
on if your new keyboard in order to search for a specific effect.
So here we are searching for the get extra MFL we can see that the return type of this for this bundle.
And it says retrieves our map of extended data from the intent of map of extent that data up means it
is going to be key value right map meaning key value here.
Right.
And it means that it's going to give us our map a key value of extended data from the Internet.
So this get through as Meffert the return value the bundle doesn't throw anything about image or bitmap
right.
So we need to actually create a variable of type bitmap inside our main activity class and we can actually
initialize our bitmap by using this map here.
That is going to be returned from the get extra Smurfette.
Let's go to the main activity class here.
Now let's go let's scroll to the top and inside this class after this line of code that actually specifies
the Chambre image Scott I can create a valuable private bitmap which is of the people with my right.
The name is bitmapped semicolon.
Right.
I didn't initialize it I just declared this value.
But let's scroll down here and let's go inside these unactivated result.
Inside this if statement after getting the bundle here from the stator I can actually just initialize
the bitmap how I can refer to this bitmap variable assignment operator.
So I told you that the GET throws method doesn't know anything about bitmap or images.
So you are 100 percent sure that there is actually a bitmap so remember that the image that is taken
by the user by using the camera is actually going to be of type bitmap.
So let's cast it to bitmap here.
OK bitmap.
And after this practice this year after this casting here I can refer to this bundle data just by using
this gets Meffert on this bundle you're going to get the value by passing the key.
So bypassing the key are going to get the value.
So that's why it is called map right.
Key value so get is going to be called on the.
And bypassing.
You can see that it says Key.
Right.
The pass the key is going to give us the value.
So said this actually to send it like this Meffert.
You can see that the arguments that we need to pass through this method is going to be off the screen
and its name is key.
So just put two coats here.
The key is going to be data right.
When the past Key data is going to give us the value it is going to be off the bitmap but that gets
me if it doesn't know anything about the bitmap.
But you are 100 percent sure it is going to be off the map so it just casts that two bitmap object and
we initialized our bitmap area.
Now after this line of code I can see IMT photo that set image bitmap bitmap.
That's it.
Let's run that application now.
So here you can see that our application is running on the simulator.
Let's take a picture.
Let's accept it's now you can see this image here.
Right.
An activity is all it is called.
And here the image is actually put inside this image of you.
That's it.
If you want to can test this up on your actual device.
So now in the next tutorial we're going to actually add another class in order to allow the user to
use these search parties in order to colorful in order to make his image and truly colorful and add
colors to this image.
Red green and blue.
So let's see how we can do that in the next story or so.
Thank you very much for watching.
If you have any questions about the concepts that I taught you so far please post the discussion in
the course and then I do my best to answer all of your questions.