public class BleSetupHelper
extends java.lang.Object
Build.VERSION_CODES.M
.
With Build.VERSION_CODES.M
you need to have Manifest.permission.ACCESS_COARSE_LOCATION
or Manifest.permission.ACCESS_FINE_LOCATION
in your AndroidManifest.xml, and also enable them at runtime, AND also make sure location services are on.
BleManager
(see the "See Also" section, which has enough links that it might give you
an idea of why BleSetupHelper
was written). As such you don't need to use it, but it comes in handy as a simple addition to most simple apps.BleManager.isLocationEnabledForScanning()
,
BleManager.isLocationEnabledForScanning_byManifestPermissions()
,
BleManager.isLocationEnabledForScanning_byRuntimePermissions()
,
BleManager.isLocationEnabledForScanning_byOsServices()
,
BleManager.turnOnLocationWithIntent_forPermissions(Activity, int)
,
BleManager.turnOnLocationWithIntent_forOsServices(Activity, int)
,
BleManager.turnOnWithIntent(Activity, int)
,
BleManager.willLocationPermissionSystemDialogBeShown(Activity)
,
https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues#android-m-issuesModifier and Type | Class and Description |
---|---|
static class |
BleSetupHelper.BluetoothEnablerImpl
This class implements all of the enabler logic that can be overridden to alter the look or the messaging of the enabler.
|
static class |
BleSetupHelper.DefaultString
Enumerates the built in strings used by the enabler to convey information to users.
|
static class |
BleSetupHelper.ErrorCode
Enumerates the various errors that can happen.
|
static class |
BleSetupHelper.Permission
Enumerates the various permissions that we will try to enable (if needed)
|
static class |
BleSetupHelper.PermissionInstance
This class holds a permission and user defined metadata.
|
static class |
BleSetupHelper.Result
This class will be passed into your
BleSetupHelper.ResultListener when the enabler finishes |
static interface |
BleSetupHelper.ResultListener
This class holds a permission and user defined metadata.
|
protected static class |
BleSetupHelper.State |
Constructor and Description |
---|
BleSetupHelper(BleManager manager,
android.app.Activity activity)
Constructor for use when you don't want a result listener.
|
BleSetupHelper(BleManager manager,
android.app.Activity activity,
BleSetupHelper.BluetoothEnablerImpl enablerImpl,
BleSetupHelper.ResultListener listener)
Constructor for use when you want a result listener, and to provide your own implementation of
the enabler, or add on to the implementation with custom permissions.
|
BleSetupHelper(BleManager manager,
android.app.Activity activity,
BleSetupHelper.ResultListener listener)
Constructor for use when you want a result listener.
|
Modifier and Type | Method and Description |
---|---|
void |
addCustomPermission(java.lang.Object metadata)
Adds a custom permission to the required permission list.
|
void |
addRequiredPermissions()
This method will populate the list of required permissions with the standard defaults.
|
protected void |
afterPermissionRequested() |
protected boolean |
checkIsEnabled(BleSetupHelper.PermissionInstance pi) |
protected boolean |
checkIsRequired(BleSetupHelper.PermissionInstance pi) |
protected void |
doneRequestingCustomPermission() |
protected void |
errorOut(BleSetupHelper.ErrorCode ec) |
protected void |
errorOut(BleSetupHelper.ErrorCode ec,
java.lang.String errorMessage) |
protected void |
finishCurrentPermission(boolean success) |
protected void |
handleUIResult(BleSetupHelper.PermissionInstance pi,
boolean result) |
protected void |
postCallback(BleSetupHelper.Result r) |
protected void |
requestNextPermission() |
protected void |
requestPermission(BleSetupHelper.PermissionInstance pi) |
static void |
runEnabler(BleManager manager,
android.app.Activity activity,
BleSetupHelper.ResultListener listener)
This function handles the creation and startup of the enabler using default options.
|
void |
setImpl(BleSetupHelper.BluetoothEnablerImpl impl)
This method allows you to set a custom implementation which can be used to implement custom
permissions, or to customize the look or text of the dialogs and toasts shown by the enabler.
|
void |
setResultListener(BleSetupHelper.ResultListener resultListener)
This method allows you to change the
BleSetupHelper.ResultListener after construction of the enabler |
protected void |
setState(BleSetupHelper.State newState) |
protected void |
showUIToEnable(BleSetupHelper.PermissionInstance pi) |
void |
start()
This method starts the enabler.
|
public BleSetupHelper(BleManager manager, android.app.Activity activity)
addRequiredPermissions()
and/or
addCustomPermission(Object)
, and then call start()
manager
- - the BleManager
to use. If it becomes null, the enabler will haltactivity
- - the Activity
to use. If it becomes null, the enabler will haltpublic BleSetupHelper(BleManager manager, android.app.Activity activity, BleSetupHelper.ResultListener listener)
addRequiredPermissions()
and/or
addCustomPermission(Object)
, and then call start()
manager
- - the BleManager
to use. If it becomes null, the enabler will haltactivity
- - the Activity
to use. If it becomes null, the enabler will haltlistener
- - the BleSetupHelper.ResultListener
that will be called when the enabler finishespublic BleSetupHelper(BleManager manager, android.app.Activity activity, BleSetupHelper.BluetoothEnablerImpl enablerImpl, BleSetupHelper.ResultListener listener)
addRequiredPermissions()
and/or
addCustomPermission(Object)
, and then call start()
manager
- - the BleManager
to use. If it becomes null, the enabler will haltactivity
- - the Activity
to use. If it becomes null, the enabler will haltlistener
- - the BleSetupHelper.ResultListener
that will be called when the enabler finishesenablerImpl
- - the BleSetupHelper.BluetoothEnablerImpl
that will be used to handle the logic of getting permissionspublic static void runEnabler(BleManager manager, android.app.Activity activity, BleSetupHelper.ResultListener listener)
manager
- - the BleManager
to use. If it becomes null, the enabler will haltactivity
- - the Activity
to use. If it becomes null, the enabler will haltlistener
- - the BleSetupHelper.ResultListener
to use. Can be null if you do not want a callbackpublic void setImpl(BleSetupHelper.BluetoothEnablerImpl impl)
impl
- - the custom implementationpublic void setResultListener(BleSetupHelper.ResultListener resultListener)
BleSetupHelper.ResultListener
after construction of the enablerresultListener
- - the new BleSetupHelper.ResultListener
public void addRequiredPermissions()
start()
is called. If you use the static utility method
runEnabler(BleManager, Activity, ResultListener)
, this will be
done for you.public void addCustomPermission(java.lang.Object metadata)
BleSetupHelper.BluetoothEnablerImpl
via setImpl(BluetoothEnablerImpl)
.
If you don't, the enabler will error out when it tries to check or enable the custom permission.
The metadata object you provide will be passed into all methods that pertain to the custom
permission. You can use this to distinguish multiple custom permissions from eachother, or
to tack on and track additional informationmetadata
- - the metadata that will accompany the custom permissionpublic void start()
protected void setState(BleSetupHelper.State newState)
protected void postCallback(BleSetupHelper.Result r)
protected void requestNextPermission()
protected void handleUIResult(BleSetupHelper.PermissionInstance pi, boolean result)
protected void finishCurrentPermission(boolean success)
protected void doneRequestingCustomPermission()
protected void afterPermissionRequested()
protected boolean checkIsEnabled(BleSetupHelper.PermissionInstance pi)
protected boolean checkIsRequired(BleSetupHelper.PermissionInstance pi)
protected void requestPermission(BleSetupHelper.PermissionInstance pi)
protected void errorOut(BleSetupHelper.ErrorCode ec)
protected void errorOut(BleSetupHelper.ErrorCode ec, java.lang.String errorMessage)
protected void showUIToEnable(BleSetupHelper.PermissionInstance pi)