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.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application <application
android:name=".application.NextcloudTalkApplication" android:name=".application.NextcloudTalkApplication"

View File

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