Skip to content

Commit

Permalink
Request Background location permission if on API level 29+ (pluscubed…
Browse files Browse the repository at this point in the history
  • Loading branch information
ErdbeerbaerLP committed Jul 1, 2023
1 parent 981a0e2 commit 8d74b19
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package="com.pluscubed.velociraptor">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ class PermissionsFragment : Fragment() {
}

enableLocationButton.setOnClickListener { v ->
requestPermissions(
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_LOCATION
)
if (Build.VERSION.SDK_INT < 29)
requestPermissions(
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_LOCATION
)
else
requestPermissions(
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION),
REQUEST_LOCATION
)
}
}

Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/com/pluscubed/velociraptor/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,19 @@ object Utils {

fun isLocationPermissionGranted(context: Context?): Boolean {
if (context != null) {
return ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
return if (Build.VERSION.SDK_INT < 29)
ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
else
ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
) == PackageManager.PERMISSION_GRANTED
}
return false
}
Expand Down

0 comments on commit 8d74b19

Please sign in to comment.