add ACCESS_COARSE_LOCATION for LocationPickerController

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-06-11 10:50:54 +02:00
parent 7803263c1d
commit 80e1bc6505
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
2 changed files with 22 additions and 19 deletions

View file

@ -71,6 +71,7 @@
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:name=".application.NextcloudTalkApplication"

View file

@ -212,8 +212,8 @@ class LocationPickerController(args: Bundle) :
}
private fun initMap() {
if (!isFineLocationPermissionGranted()) {
requestFineLocationPermission()
if (!isLocationPermissionsGranted()) {
requestLocationPermissions()
}
binding.map.setTileSource(TileSourceFactory.MAPNIK)
@ -370,29 +370,31 @@ class LocationPickerController(args: Bundle) :
})
}
private fun isFineLocationPermissionGranted(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return if (PermissionChecker.checkSelfPermission(
context!!,
Manifest.permission.ACCESS_FINE_LOCATION
) == PermissionChecker.PERMISSION_GRANTED
) {
Log.d(TAG, "Permission is granted")
true
} else {
Log.d(TAG, "Permission is revoked")
false
}
private fun isLocationPermissionsGranted(): Boolean {
fun isCoarseLocationGranted(): Boolean {
return PermissionChecker.checkSelfPermission(
context!!,
Manifest.permission.ACCESS_COARSE_LOCATION) == PermissionChecker.PERMISSION_GRANTED
}
fun isFineLocationGranted() : Boolean {
return PermissionChecker.checkSelfPermission(
context!!,
Manifest.permission.ACCESS_FINE_LOCATION) == PermissionChecker.PERMISSION_GRANTED
}
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
isCoarseLocationGranted() && isFineLocationGranted()
} else {
Log.d(TAG, "Permission is granted")
return true
true
}
}
private fun requestFineLocationPermission() {
private fun requestLocationPermissions() {
requestPermissions(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
),
REQUEST_PERMISSIONS_REQUEST_CODE
)