Мой код:
Код: Выделить всё
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
locationHandler = STLocationHandler(this, this)
// If we fall straight through then we have permission
if (ContextCompat.checkSelfPermission(this, LOCATION_SERVICE) == PackageManager.PERMISSION_GRANTED) {
setUpAbly()
} else {
// Double check we can get permission
// If we don't then we'll get a dialog, the callback is then executed in the MainActivity
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION), GPS_REQUEST_CODE)
}
setContent {
StimeTheme {
MainLayout()
}
}
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
< /code>
и < /p>
@RequiresPermission(allOf = [Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION])
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array,
grantResults: IntArray,
deviceId: Int
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults, deviceId)
if (requestCode != GPS_REQUEST_CODE) { return }
if (locationHandler.setPermissions(permissions, grantResults)) {
// We have permission!
setUpAbly()
} else {
showGPSAlert.value = true
}
}
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/796 ... not-called
Мобильная версия