Home > Enterprise >  My kotlin code to access the camera is giving this error ->unsolved reference:PERMISSION_GRANTED.
My kotlin code to access the camera is giving this error ->unsolved reference:PERMISSION_GRANTED.

Time:05-23

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]

CodePudding user response:

Replace:

packageManager.PERMISSION_GRANTED

with:

PackageManager.PERMISSION_GRANTED

IOW, use a capital P, not a lowercase p, in the class name PackageManager.

  • Related