应为索引元素Kotlin

efzxgjgh  于 2022-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(116)

有谁能告诉我如何解决“期待一个索引元素Kotlin”这个问题吗?...........................................................................

package com.example.imagetotext

import android.Manifest
import android.Manifest.permission.CAMERA
import android.Manifest.permission_group.CAMERA
import android.content.pm.PackageManager
import android.hardware.SensorPrivacyManager.Sensors.CAMERA
import android.media.MediaRecorder.VideoSource.CAMERA
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

class MainActivity : AppCompatActivity() {
    private lateinit var btn1 : Button
    private lateinit var btn2: Button
    private lateinit var txtview : TextView
    private val  REQUEST_CAMERA_CODE : Int = 100

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        btn1=findViewById(R.id.buttoncapture);
        btn2=findViewById(R.id.buttoncopy);
        txtview=findViewById(R.id.textdata);

        if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=PackageManager.PERMISSION_GRANTED)
        {
           ActivityCompat.requestPermissions(this, String[] {
               Manifest.permission.CAMERA
           }, REQUEST_CAMERA_CODE)
        }
    }
}
mspsb9vt

mspsb9vt1#

if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=PackageManager.PERMISSION_GRANTED)
    {
        ActivityCompat.requestPermissions(this,  arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA_CODE)
    }

相关问题