<uses-permission android:name="android.permission.CAMERA" />
class PermissionActivity : AppCompatActivity() {
private lateinit var binding: ActivityPermissionBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPermissionBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.buttonpermission.setOnClickListener {
val cameraPermissionCheck =
ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA)
if (cameraPermissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.CAMERA),
1000
)
}
else {
Log.e("permissionss", "권한이 이미 있음")
}
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.e("permissionss", "승락")
} else {
Log.e("permissionss", "거부")
}
}
}
}