Consider this Kotlin snippet for requesting location permission in an Android app. What will the app display if the user denies the location permission?
val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
if (isGranted) {
textView.text = "Permission granted"
} else {
textView.text = "Permission denied"
}
}
requestPermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)Think about what happens when the permission callback receives false.
If the user denies the permission, the callback receives false, so the TextView text is set to "Permission denied".
Android offers different location providers. Which one typically provides the most accurate location data?
Think about which source uses satellites directly.
The GPS provider uses satellites and usually gives the most accurate location outdoors.
In an Android app, if you start location updates in the onCreate method of an Activity and never stop them, what is the likely result?
Consider what happens if you don't remove location updates explicitly.
Without stopping location updates, they continue running, draining battery even if the app is not visible.
Which Intent action correctly opens the app's settings page so the user can enable location permission manually?
Think about how to open the specific app's settings page.
Using ACTION_APPLICATION_DETAILS_SETTINGS with the app package Uri opens the app's settings page.
Examine this Kotlin code snippet. Why does it cause a crash when run?
val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
fusedLocationClient.lastLocation.addOnSuccessListener { location ->
if (location != null) {
textView.text = "Lat: ${location.latitude}, Lon: ${location.longitude}"
} else {
textView.text = "Location not available"
}
}Think about what happens if the location is not available yet.
The lastLocation can be null if no location is cached yet. Accessing latitude without null check causes NullPointerException.