public abstract class NAPlatform extends Object
This is the NewAer Proximity Platform. It contains methods for initializing the platform, getting the platform for a given context, enabling, starting and stopping scanning for various device types.
It also contains methods for getting and creating devices, rules, actions and plugins. However, we have provided static convenience methods, which are almost always shorter to type, especially if you don't already have a platform instance. We suggest you use those.
NewAer uses Semantic Versioning.
Modifier and Type | Field and Description |
---|---|
static String |
SDK_VERSION_CODE |
static int |
SDK_VERSION_MAJOR
The major version number of the platform.
|
static int |
SDK_VERSION_MINOR
The minor version number of the platform.
|
static int |
SDK_VERSION_PATCH
The patch number of the platform.
|
Modifier | Constructor and Description |
---|---|
protected |
NAPlatform()
Only subclasses may construct.
|
Modifier and Type | Method and Description |
---|---|
static void |
destroy(Context context)
Shut down the platform, stopping all scans and dereferencing.
|
abstract void |
enablePrivateAnnounce(boolean announce) |
static NAPlatform |
get(Context context)
Returns an instance of the NewAer Platform.
|
abstract List<NADevice> |
getAllDevices()
Returns a collection of devices the platform has recently seen.
|
abstract List<NADevice> |
getAllDevicesByType(NADeviceType type)
Returns a collection of devices the platform has recently seen.
|
abstract String |
getAppId() |
abstract NADevice |
getDevice(String id)
Retrieves a device by it's id.
|
abstract String |
getFriendlyName()
Returns the friendly name for this device.
|
abstract byte[] |
getInfo() |
abstract String |
getNewAerId()
Returns a unique identifier which will be seen by others with scanning.
|
abstract Set<NAScanType> |
getPersistentScanTypes()
Returns an
EnumSet of NAScanType s previously marked as persistent. |
abstract int |
getScanInterval() |
abstract long |
getScanTime() |
static String |
getVersion() |
abstract boolean |
hasHardware(NADeviceType type)
Returns true if the device has hardware required for discovering a particular
device type.
|
static void |
init(Context context,
String appKey,
String packageName,
List<NAScanType> defaultEnabledTypes,
NARegistrationListener listener)
Initialize the platform with specified device types enabled.
|
static void |
init(Context context,
String appKey,
String packageName,
NARegistrationListener listener)
Initializes the platform.
|
abstract boolean |
isEnabled(NAScanType type)
Returns if scanning is enabled for the given type.
|
static boolean |
isInitialized(Context context)
Check to see if an instance of NewAer is currently operation
|
abstract boolean |
isScanning(NADeviceType type)
Returns true if scans are running for the given device
type, i.e.
|
abstract void |
registerDeviceObserver(DataSetObserver observer)
Register an observer to be notified whenever a change
occurs on a device or device list which is tagged.
|
abstract void |
registerDeviceStatusListener(NADeviceStatusListener listener)
Register a listener which will be notified when a device status changes.
|
abstract void |
registerMessageListener(NAMessageListener listener)
Registers a listener for messages received.
|
abstract void |
registerScanListener(com.newaer.sdk.proximity.NAScanListener listener)
Register a listener which will be notified when a scan begins.
|
abstract boolean |
sendMessage(NAMessage message)
Sends a message over BLE to a NewAer device.
|
abstract void |
setDebugLogging(boolean enabled)
Enables or disables some internal logging in the SDK.
|
abstract void |
setFriendlyName(String name)
Sets the friendly name for this device.
|
abstract void |
setInfo(byte[] info)
Sets the additional information for this device.
|
abstract void |
setScanInterval(int interval)
Sets the scan interval in seconds.
|
abstract void |
setScanTime(long scanTime)
Sets the scan time in seconds.
|
abstract void |
setScanTypeAsPersistent(NAScanType... types)
Marks these
NAScanType s as "persistent". |
abstract void |
startRemoteScan() |
abstract void |
startScan()
Start scans for all device types.
|
abstract void |
startScanWithScanTypes(NAScanType... deviceTypes)
Start scans for specified device types
|
abstract void |
stopRemoteScan() |
abstract void |
stopScan()
Stop scans for all device type
|
abstract void |
stopScanWithScanTypes(NAScanType... deviceTypes)
Stop scans for specified device types, except BLUETOOTH_LE.
|
abstract void |
unregisterDeviceObserver(DataSetObserver observer)
Unregister a device observer.
|
abstract void |
unregisterDeviceStatusListener(NADeviceStatusListener listener)
Removes a listener previously registered.
|
abstract void |
unregisterMessageListener(NAMessageListener listener)
Unregisters a listener for messages received.
|
abstract void |
unregisterScanListener(com.newaer.sdk.proximity.NAScanListener listener)
Removes a listener previously registered.
|
public static final int SDK_VERSION_MAJOR
The major version number of the platform.
public static final int SDK_VERSION_MINOR
The minor version number of the platform.
public static final int SDK_VERSION_PATCH
The patch number of the platform.
public static final String SDK_VERSION_CODE
public static String getVersion()
public static NAPlatform get(Context context)
context
- The Context used to get the platform.IllegalStateException
- if the platform has not yet been initialized.public static void init(Context context, String appKey, String packageName, NARegistrationListener listener)
Initializes the platform. All device types are disabled by default.
This method is most easily called in your Application.onCreate()
to initialize the NewAer Platform.
You can extend NAProximityApp
to make it easy to call this
method at the correct time for your application.
context
- the context to initialize withappKey
- the application keylistener
- the listener for registration events.IllegalStateException
- if the platform has already been initialized.public static void init(Context context, String appKey, String packageName, List<NAScanType> defaultEnabledTypes, NARegistrationListener listener)
Initialize the platform with specified device types enabled. Once setEnabled(type) has been called, that value will be persist.
context
- the context to initialize forappKey
- the application keydefaultEnabledTypes
- scan types to enable by defaultlistener
- the listener for registration events.IllegalStateException
- if the platform has already been initialized.public static void destroy(Context context)
Shut down the platform, stopping all scans and dereferencing. This will throw an exception if the platform is not current running.
context
- that the platform was created inIllegalStateException
- If there is no current instance of the platformpublic static boolean isInitialized(Context context)
Check to see if an instance of NewAer is currently operation
context
- that the platform was created inpublic abstract String getNewAerId()
Returns a unique identifier which will be seen by others with scanning.
This id can be used to identify a device running the NewAer platform.
public abstract String getAppId()
public abstract void registerDeviceStatusListener(NADeviceStatusListener listener)
listener
- the listener to be notified.public abstract void unregisterDeviceStatusListener(NADeviceStatusListener listener)
listener
- the listener to remove.public abstract void registerScanListener(com.newaer.sdk.proximity.NAScanListener listener)
listener
- the listener to be notified.public abstract void unregisterScanListener(com.newaer.sdk.proximity.NAScanListener listener)
listener
- the listener to remove.public abstract void setScanTypeAsPersistent(NAScanType... types)
NAScanType
s as "persistent". This means that if the underlying hardware
supporting the scantype is turned off (e.g., the user turns off WiFi through the OS settings).
NOTE 1: Calling this method repeatedly with different values overwrites the previous values stored.
NOTE 2: stopScanWithScanTypes(NAScanType...)
will underlyingly remove
any scantypes set here. So, for example, calling:
And then calling
NAPlatorm.startScanWithScanTypes(NAScanType.WIFI);
NAPlatform.setScanTypeAsPersistent(NAScanType.WIFI);
will result in the following occurring:
NAPlatform.stopScanWithScanTypes(NAScanType.WIFI);
(Assuming that
NAPlatform.setScanTypeAsPersistent(null);
NAScanType.WIFI
was the only ScanType set as persistent)
NOTE 3: Calling NAPlatorm.startScanWithScanTypes again will NOT re-set that scantype as persistent
types
- public abstract Set<NAScanType> getPersistentScanTypes()
EnumSet
of NAScanType
s previously marked as persistent.public abstract boolean hasHardware(NADeviceType type)
Returns true if the device has hardware required for discovering a particular device type.
type
- the type to check forpublic abstract boolean isEnabled(NAScanType type)
Returns if scanning is enabled for the given type.
type
- the type to check forpublic abstract boolean isScanning(NADeviceType type)
Returns true if scans are running for the given device
type, i.e. the system radio is turned on. The type must
also be enabled in order to scan. See startScanWithScanTypes(NAScanType...)
type
- the type to inquire aboutpublic abstract void startScan()
public abstract void startScanWithScanTypes(NAScanType... deviceTypes)
deviceTypes
- public abstract void stopScan()
public abstract void stopScanWithScanTypes(NAScanType... deviceTypes)
Stop scans for specified device types, except BLUETOOTH_LE.
deviceTypes
- public abstract void startRemoteScan()
public abstract void stopRemoteScan()
public abstract void enablePrivateAnnounce(boolean announce)
public abstract void setScanInterval(int interval)
Sets the scan interval in seconds.
A scan is started every interval seconds.
interval
- the scan interval in secondspublic abstract int getScanInterval()
public abstract void setScanTime(long scanTime)
Sets the scan time in seconds.
The BLE scanner is held on for scanTime seconds.
This should be less then the interval or a scan will only be performed every other interval, since a full scan takes slightly longer than the time the BLE Scanner is running due to book keeping.
scanTime
- the time the BLE scanner is held on.public abstract long getScanTime()
public abstract List<NADevice> getAllDevices()
Returns a collection of devices the platform has recently seen. Devices in this list may not be in subsequent calls to the method.
This devices in this list are actively managed by the platform. This means that the state of devices in this list may change at any time.
This list is intended to allow applications to display a list of recently seen devices for tagging.
public abstract List<NADevice> getAllDevicesByType(NADeviceType type)
Returns a collection of devices the platform has recently seen. Devices in this list may not be in subsequent calls to the method.
This devices in this list are actively managed by the platform. This means that the state of devices in this list may change at any time.
This list is intended to allow applications to display a list of recently seen devices for tagging.
type
- the type of devices to getpublic abstract void registerDeviceObserver(DataSetObserver observer)
Register an observer to be notified whenever a change occurs on a device or device list which is tagged.
The observer will be called when any of the get device lists has a change in membership or state of a member.
observer
- the observer to register.public abstract void unregisterDeviceObserver(DataSetObserver observer)
observer
- the observer to register.public abstract NADevice getDevice(String id)
id
- the id of the device to retrieve.public abstract boolean sendMessage(NAMessage message)
message
- NADeviceType.NEWAER
device.public abstract void setDebugLogging(boolean enabled)
enabled
- true to enable logging.public abstract void setInfo(byte[] info)
info
- the info to setIllegalArgumentException
- if info.length > 90public abstract byte[] getInfo()
public abstract String getFriendlyName()
setFriendlyName(String)
.public abstract void setFriendlyName(String name)
name
- the friendly name to setIllegalArgumentException
- if name.getBytes("UTF-8").length > 256public abstract void registerMessageListener(NAMessageListener listener)
listener
- the listener to registerpublic abstract void unregisterMessageListener(NAMessageListener listener)
listener
- the listener to unregister