public class SystemRequirementsHelper
extends java.lang.Object
isBluetoothLeAvailable(Context)
isBluetoothEnabled(Context)
isLocationServiceForBluetoothLeEnabled(Context)
hasAnyLocationPermission(Context)
Estimote SDK periodically checks if following conditions are checked. If not met, an error log is printed.
You can manually check all those conditions via checkAllPermissions(Context)
.
Constructor and Description |
---|
SystemRequirementsHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkAllPermissions(android.content.Context context)
Returns false is any of following conditions are not met:
Bluetooth permissions are granted (android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN).
BeaconService is declared in AndroidManifest.xml.
If running on Android M or later, Location Services must be turned on.
If running on Android M or later and your app is targeting SDK < 23 (M),
any location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION)
must be granted for background beacon detection.
If running on Android M or later and your app is targeting SDK >= 23 (M),
any location permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION)
must be granted.
|
static boolean |
hasAnyLocationPermission(android.content.Context context)
Returns true if app has permission granted to ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION.
|
static boolean |
isBluetoothEnabled(android.content.Context context)
Returns true if Bluetooth is enabled on the device.
|
static boolean |
isBluetoothLeAvailable(android.content.Context context)
Returns true if device supports Bluetooth Low Energy.
|
static boolean |
isForegroundApp(android.content.Context context)
This method was copied from Android's code: com.android.bluetooth.Utils#isForegroundApp.
|
static boolean |
isLocationServiceForBluetoothLeEnabled(android.content.Context context)
Returns true if Location Services are enabled and required for Bluetooth LE scanning.
|
static boolean |
shouldShowCoarseLocationRequestPermissionRationale(android.app.Activity activity)
Gets whether you should show UI with rationale for requesting ACCESS_COARSE_LOCATION permission.
|
public static boolean isBluetoothLeAvailable(android.content.Context context)
context
- Android context.public static boolean isBluetoothEnabled(android.content.Context context)
If not, you should ask user to enable it via:
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
context
- Android context.public static boolean isLocationServiceForBluetoothLeEnabled(android.content.Context context)
Note: on Android L and earlier there is no need to have Location Services enabled for Bluetooth LE scanning and this method returns true.
If not, you should ask user to enable it:
// It is recommended to show dialog with explanation. // Dialog title: Requesting location access // Dialog message: Detecting beacons requires Location to be enabled.We'll never access your GPS location without your knowledge. // OK button: Go to settings to enable // Cancel button: I don't want to do this now Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); activity.startActivity(intent);
context
- Android context.public static boolean hasAnyLocationPermission(android.content.Context context)
context
- Android context.public static boolean checkAllPermissions(android.content.Context context)
BeaconService
is declared in AndroidManifest.xml.If this method returns false, error with detailed description will be printed in the Android logs.
public static boolean shouldShowCoarseLocationRequestPermissionRationale(android.app.Activity activity)
On Android L and earlier this method always returns false. Runtime permission request rationale was introduced on Android M.
activity
- The target activity.public static boolean isForegroundApp(android.content.Context context)
SecurityException
for accessing running tasks
but for some reason it works.
Just to be bullet-proof if there is any exception throw, method will return true.