【发布时间】:2021-04-20 21:17:48
【问题描述】:
您好,当应用程序启动时,我对我的 forYou 片段进行了权限检查,并且您授予权限,它会进行 api 调用并获取您当前位置的天气问题是我必须切换片段以获取呼叫并切换再次在reclyerview中显示它,问题是当我授予它不执行api的位置的权限时,我必须刷新片段
fusedLocationClient.lastLocation.addOnSuccessListener(requireActivity()) { location ->
if (location != null) {
currentLocation = location
val currentLatLng = LatLng(location.latitude, location.longitude)
val currentAddress = getAddress(location.latitude, location.longitude)
Log.d("TAG", "klagenfurt : ${currentAddress}")
retrofitOneCallResponse(location.latitude, location.longitude, currentAddress)
dataService.getFavorites(this)
}
}
if (ActivityCompat.checkSelfPermission(
requireContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(
requireActivity(),
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),
MapViewFragment.LOCATION_PERMISSION_REQUEST_CODE
)
return
}
【问题讨论】:
标签: android google-maps kotlin android-fragments