‫Hello, my friends.
‫We've seen in the previous videos how to create the camera provider future and how to initialize the
‫widgets.
‫Now we are going to continue creating our methods and we are going to create a bind the preview method
‫and the on request permission result in this video.
‫So let's start by requesting the permissions from the user.
‫Since we need to access the camera, so we need to request from the user to allow us to access access
‫this camera according to the Android system.
‫So I will start by requires or or we can select by on request permission a result I override this method
‫on request permission result or you can click on add plus insert and you can select override method
‫and search for on result and request permission result.
‫This is very simple.
‫So what we have done is overriding this method.
‫Now, under the super here, I will start requesting the code, checking for the request code.
‫If the request code equal equal to one one.
‫And this is the, the request code if we hover on it.
‫If we select on the request code, this is the request code one.
‫One means it is guaranteed.
‫So this is guaranteed and that grant result dot length greater than zero.
‫What we will do, we will make a an instance from the process camera provider I'll name it plus camera
‫provider equal to null.
‫Now I will start by try and catch.
‫So this is the try because we are dealing with the process camera provider and now we are going to initialize
‫this camera provider and cast it to process camera provider and camera provider future to get method.
‫Okay we have an error here out plus enter to add the catch clothes and the catch clause have been added
‫successfully that now everything is working fine.
‫Now I will use the blind preview method here and I will pass the process camera provider.
‫Okay.
‫We have used the blind preview here and blind preview method.
‫Now let's create this method l plus enter to create the preview bind.
‫In the main activity.
‫And this is our method.
‫Okay.
‫Now.
‫This blind preview method.
‫We will start by creating an instance from the preview preview.
‫This is from Android X Camera.
‫Preview.
‫You preview.
‫Dot builder.
‫Dot build
‫camera selector
‫camera selector equal to new camera selector dot builder dot requires lens facing and we pass the camera
‫selector dot lens facing the front.
‫Or the back.
‫But since we are going to scan the barcode with our phone so the item will be facing the front, the
‫back camera.
‫Okay.
‫So I will use the lens facing back.
‫Okay.
‫And here I will remove this space and I use the build method now.
‫The A preview here the preview DOT set service provider preview view dot get service provider and image
‫capture.
‫Image capture equal to new image capture dot builder since we are going to capture the image in order
‫to get the data from it.
‫So we need to detect it and and store this image captured inside an instance of the image capture
‫object.
‫So then we need to analyze this image.
‫So I captured the image.
‫I need to analyze it.
‫How to make it, how to make this analyze and this analysis using these these instances.
‫So I started by image capture and then I bought a by making an image analysis object, I will continue
‫analyzing the image and detecting the data and stored inside the QR code.
‫Remember, we need to capture, then analyze and this is by logic, image analysis and analyzer.
‫Despite using the analyzer.
‫Now I will use the builder.
‫Here I will set target resolution, new size and the new here 1280 and 720 OC size is capital letter.
‫This is from the documentations of the camera x.
‫Labor setback pressure strategy to image analysis dot strategy keep only latest.
‫So what if you captured many images?
‫We need the last image to be analyzed and detecting the QR code data from it.
‫Okay, so this is what we why we use the setback pressure strategy.
‫Now the built image analysis here, the set analyzer, camera, executor and analyzer.
‫Now I will use the process camera provider, dot unbind all and then I will use the same process.
‫Camera provider.
‫Dot bind to lifecycle this camera selector and preview.
‫And the fourth parameter that I need to make to pass is image capture and then the image analysis.
‫So I'm binding all of these capturing and analysis to the life cycle of the camera provider.
‫This is the document according to the documentations of this library, camera x.
‫We we have here an error required type analyzer provided image analyzer.
‫This will be solved in the next video.
‫By extending this class, the image analyzer from image analysis dot analyzer.
‫So I need to make this this object from my image analyzer as an image and and analysis analyzer.
‫This is provided by the camera x.
‫An Android X camera package.
‫So thank you, guys.
‫Hope I see you.