Используйте this@RequiresLocation
вместо RequiresLocation.class
Попробуйте это
ActivityCompat.requestPermissions(
this@RequiresLocation,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
requestCode)
Или
private fun requestLocationPermission() {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
requestCode) // coming up in red
}
ОБНОВЛЕНИЕ
class RequiresLocation : AppCompatActivity() {
val requestCode: Int = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_requires_location)
turnOnLocationButton.setOnClickListener {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission has already been granted", Toast.LENGTH_SHORT).show()
}
else {
requestLocationPermission()
}
}
}
private fun requestLocationPermission() {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
requestCode) // coming up in red
}
}