Use of Camera

We can make use of the Camerax API

Since out application is a software and the camera is a hardware, we need to bind it with our application
On doing this we will get signal in our application which we need to show in our application  using the PreviewView and then use ImageCapture to capture the image that's been displayed on the screen and then store the file as required
we need to add the camerax dependencies namely camera-camera, camera-lifecycle, camera-view
We need to have camera permission
<Uses-permission> android.permission.camera
<Uses-feature> android.hardware.camera.any

In the layout we can add a button to capture the image and a PreviewView avaialble from androidx.camera.view.PreviewView


In the activity, Check if the permissions are granted or not 

var camera : Camera

in onCreate(){

if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)==PERMISSION_GRANTED) {

startCamera()

} else {

    ActvitiyCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), requestcode(0))

    }


capturebtn onclicklistener {

    TakePicture()

}

}

override
onRequestPermissionsResult(requestCode:Int, permissions:Array<out, String>, grantResults:IntArray) {

    if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)==PERMISSION_GRANTED) {

    startCamera()

} else {

    ActvitiyCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), requestcode(0))

    }

}


startCamera() {

}


takePicture() {

}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API