'My kotlin code to access the camera is giving this error ->unsolved reference:PERMISSION_GRANTED.Please help me to solve the error
Below is my code that contains the error while I was following an youtube video (link provided) I got an error when I used packageManager.PERMISSION_GRANTED the code contains error called "Unresolved reference: PERMISSION_GRANTED".PLease help to solve the error fast
package com.example.machineleaarningapp
import android.content.ActivityNotFoundException
import android.content.Intent
import android.graphics.Camera
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.MediaStore
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import com.example.machineleaarningapp.databinding.ActivityMainBinding
import org.w3c.dom.Text
import java.security.Permission
class MainActivity : AppCompatActivity() {
private lateinit var binding:ActivityMainBinding
private lateinit var imageView: ImageView
private lateinit var button: Button
private lateinit var tvOutput:TextView
private val GALLERREQUESTCODE=123
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding= ActivityMainBinding.inflate(layoutInflater)
val view=binding.root
setContentView(R.layout.activity_main)
setContentView(view)
imageView=binding.imageView
tvOutput=binding.resulttv
button=binding.capture
val buttonLoad=binding.Loadimage
button.setOnClickListener{
if(ContextCompat.checkSelfPermission(this,android.Manifest.permission.CAMERA)==packageManager.PERMISSION_GRANTED){
takePicturePreview.lauch(null)
}
else{
requestPermission.launch(android.Manifest.permission.CAMERA)
}
}
}
}[I was following code on this youtube channel[\]\[1\]][1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
