public class SystemRequirementsChecker
extends java.lang.Object
Depending on Android platform you need different permissions to be granted. It is recommended to implement future proof Android M runtime permissions model.
In order to reliably detect beacons following conditions must be met:
BeaconService
is declared in AndroidManifest.xml.
This is done automatically if you use Estimote SDK.If you start detecting beacons and some of the requirements are not met, there will not be any
exception raised. From time to time SDK will put warning in device logs what is missing. Once
all requirements are met, beacon detection (via BeaconManager
will automatically start
detecting beacons without
This class provides check(Context, Callback)
method for checking all requirements. Its callback is
executed synchronously and provides information about not met requirements in very readable way.
Please do read comments on SystemRequirementsChecker.Callback
methods what is the best way handle lack of permissions,
access rights.
If you are looking for static helper methods for checking permissions and other requirements,
SystemRequirementsHelper
offers those.
This class also provides checkWithDefaultDialogs(Activity)
method which checks for
all requirements and does show user dialogs to grant permissions, enable Bluetooth or Location Services.
It is a great and convenient way of making sure that your app has everything needed to detect beacons.
SystemRequirementsHelper
Modifier and Type | Class and Description |
---|---|
static interface |
SystemRequirementsChecker.Callback |
static class |
SystemRequirementsChecker.Requirement |
Constructor and Description |
---|
SystemRequirementsChecker() |
Modifier and Type | Method and Description |
---|---|
static boolean |
check(android.content.Context context,
SystemRequirementsChecker.Callback callback)
Checks if all requirements are met for beacon detection across all Android versions (runtime permissions
on Android M, Bluetooth enabled, Location Services enabled on Android M).
|
static boolean |
checkWithDefaultDialogs(android.app.Activity activity)
Checks if all requirements are met for beacon detection across all Android versions and provides
default dialogs for asking for permissions and access.
|
public static boolean check(android.content.Context context, SystemRequirementsChecker.Callback callback)
SystemRequirementsChecker
docs for full explanation.
This method invokes callback synchronously, immediately upon invoking.
If it is invoked in your Activity, it is recommended to invoke it on Activity.onResume()
.
Callback is invoked always, if all requirements are met it receives empty list.
context
- Android context.callback
- Callback that is synchronously invoked with missing requirements for beacon detection.public static boolean checkWithDefaultDialogs(android.app.Activity activity)
Checks if all requirements are met for beacon detection across all Android versions and provides default dialogs for asking for permissions and access.
This is convenient method to check and to ask for all rights to detect beacons. If you want to
provide your logic for asking for permissions, rights, you need to use check(Context, Callback)
.
You need to invoke this method in your Activity.onResume()
method.
Whenever this method is invoked in your Activity.onResume()
it checks if all
requirements are met using check(Context, Callback)
. If there is at least one requirement
not met, it launches transparent activity which asks user to grant permissions, enable Bluetooth etc.
Please note that your activity will receive Activity.onPause()
if there any of requirements
are not met.
For location permissions it asks user to grant permission to ACCESS_COARSE_LOCATION.
If user denies turning Bluetooth one, it will stop asking again, until application is restarted.
activity
- Target activity.