-
public final class PermissionsManager
Helper class to manage app permissions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
PermissionsManager.Companion
-
Field Summary
Fields Modifier and Type Field Description private final Array<String>
locationPermissions
private final Array<String>
bluetoothPermissions
-
Constructor Summary
Constructors Constructor Description PermissionsManager()
-
Method Summary
Modifier and Type Method Description final Array<String>
getLocationPermissions()
final Array<String>
getBluetoothPermissions()
final Unit
registerLocationPermissionsListener(ComponentActivity componentActivity, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for location permissions requests. final Unit
registerLocationPermissionsListener(Fragment fragment, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for location permissions requests. final Unit
requestLocationPermissions()
Launches intent to ask user for location permissions, see locationPermissions. final Unit
registerBluetoothPermissionsListener(ComponentActivity componentActivity, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for bluetooth permissions requests. final Unit
registerBluetoothPermissionsListener(Fragment fragment, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for bluetooth permissions requests. final Unit
requestBluetoothPermissions()
Launches intent to ask user for bluetooth permissions, see bluetoothPermissions. final Unit
onDestroy()
Unregisters all listeners and destroys all related instances. final Boolean
hasLocationPermissions(Context context)
Checks location permissions, see locationPermissions. final Boolean
hasBluetoothPermissions(Context context)
Checks bluetooth permissions, see bluetoothPermissions. -
-
Method Detail
-
getLocationPermissions
final Array<String> getLocationPermissions()
-
getBluetoothPermissions
final Array<String> getBluetoothPermissions()
-
registerLocationPermissionsListener
final Unit registerLocationPermissionsListener(ComponentActivity componentActivity, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for location permissions requests.
This must only be called once.
Recommended calling this method in your activity's onCreate method.
- Parameters:
componentActivity
- ComponentActivity instance.onAllowed
- Callback when grants all permissions.onDenied
- Callback when denies all or at least one permission.
-
registerLocationPermissionsListener
final Unit registerLocationPermissionsListener(Fragment fragment, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for location permissions requests.
This must only be called once.
Recommended calling this method in your fragment's onCreateView method.
- Parameters:
fragment
- Fragment instance.onAllowed
- Callback when grants all permissions.onDenied
- Callback when denies all or at least one permission.
-
requestLocationPermissions
final Unit requestLocationPermissions()
Launches intent to ask user for location permissions, see locationPermissions.
This will open a permissions' dialog for each permission requested.
-
registerBluetoothPermissionsListener
final Unit registerBluetoothPermissionsListener(ComponentActivity componentActivity, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for bluetooth permissions requests.
This must only be called once.
Recommended calling this method in your activity's onCreate method.
- Parameters:
componentActivity
- ComponentActivity instance.onAllowed
- Callback when grants all permissions.onDenied
- Callback when denies all or at least one permission.
-
registerBluetoothPermissionsListener
final Unit registerBluetoothPermissionsListener(Fragment fragment, Function1<Map<String, Boolean>, Unit> onAllowed, Function1<Map<String, Boolean>, Unit> onDenied)
Registers a listener for bluetooth permissions requests.
This must only be called once.
Recommended calling this method in your fragment's onCreateView method.
- Parameters:
fragment
- Fragment instance.onAllowed
- Callback when grants all permissions.onDenied
- Callback when denies all or at least one permission.
-
requestBluetoothPermissions
final Unit requestBluetoothPermissions()
Launches intent to ask user for bluetooth permissions, see bluetoothPermissions.
This will open a permissions' dialog for each permission requested.
-
onDestroy
final Unit onDestroy()
Unregisters all listeners and destroys all related instances.
Invoke this in your activity / fragment onDestroy method.
-
hasLocationPermissions
final Boolean hasLocationPermissions(Context context)
Checks location permissions, see locationPermissions.
- Parameters:
context
- Application, activity or fragment context.
-
hasBluetoothPermissions
final Boolean hasBluetoothPermissions(Context context)
Checks bluetooth permissions, see bluetoothPermissions.
- Parameters:
context
- Application, activity or fragment context.
-
-
-
-