public class ProximityKitManager extends Object
ProximityKitManager
instance is the primary interface for working with Proximity Kit
cloud data. This provides access to the Kit
object and serves as the central registration
point for notifications of related beacon/geofence events.
For details about the available notifications see the ProximityKitMonitorNotifier
,
ProximityKitRangeNotifier
, ProximityKitGeofenceNotifier
, and ProximityKitSyncNotifier
.
To initialize a Proximity Kit manager you will need the SDK settings for your kit. These can be
found under the kit settings on the Proximity
Kit server.
The easiest way to create a KitConfig
is to build a Map
or Properties
of the settings (see KitConfig
for the full list of available settings):
Map<String, String> settings = new HashMap<>();
// or Properties settings = new Properties();
settings.put(
KitConfig.CONFIG_API_TOKEN,
"PROXIMITY KIT API TOKEN HERE"
);
settings.put(
KitConfig.CONFIG_API_URL,
"https://proximitykit.radiusnetworks.com/api/kits/YOUR_KIT_ID"
);
KitConfig kitConfig = new KitConfig(settings);
You can then use the following method to instantiate a singleton ProximityKitManager
:
public class SampleApp extends Application implements ProximityKitMonitorNotifier {
// Storage for an instance of the manager
private static volatile ProximityKitManager pkManager = null;
// Object to use as a thread-safe lock
private static final Object SHARED_LOCK = new Object();
@Override
public void onCreate() {
super.onCreate();
// ... kit configuration created per above
// Standard double check singleton initialization pattern
if (null == pkManager) {
synchronized (SHARED_LOCK) {
if (null == pkManager) {
pkManager = ProximityKitManager.getInstance(
getApplicationContext(),
kitConfig
);
}
}
}
pkManager.setProximityKitMonitorNotifier(this);
pkManager.start();
}
}
To receive callbacks when interesting things happen implement one of more of the notifier
interfaces: ProximityKitMonitorNotifier
, ProximityKitRangeNotifier
, ProximityKitGeofenceNotifier
, and ProximityKitSyncNotifier
. And provide that instance
to the manager via on of the notifier setters.
WARNING: the current design internally implements the ProximityKitManager
as a singleton. Do NOT assume that this will
always be the case. As per the example above we strongly recommend that you keep track of your
own singleton instance. This way when the behavior does change your app will not be affected.
Be aware that calling ProximityKitManager.getInstance(Context, KitConfig)
more than once will
replace the existing singleton instance. This may result in unexpected / undefined
behavior for your app.KitConfig
,
Proximity Kit Overviewandroid.os.Build.VERSION.SDK_INT
was added in this API levelModifier | Constructor and Description |
---|---|
protected |
ProximityKitManager()
Deprecated.
Not for public use. As of 0.10.0, replaced by
ProximityKitManager.getInstance(Context,
KitConfig) |
protected |
ProximityKitManager(Context context)
Deprecated.
Not for public use. As of 0.10.0, replaced by
ProximityKitManager.getInstance(Context,
KitConfig) |
Modifier and Type | Method and Description |
---|---|
void |
clearPartnerIdentifier()
Deprecated.
As of 0.10.0, replaced by
ProximityKitManager.getInstance(Context, KitConfig) |
static void |
debugOn()
Turns debugging on for geofences and beacons.
|
void |
disableGeofences()
Explicitly disable geofence support.
|
void |
enableGeofences()
Explicitly enable geofence support.
|
com.radiusnetworks.proximity.proximitykit.BeaconAdapter |
getBeaconAdapter() |
BeaconManager |
getBeaconManager()
Convenience method to access the beacon manager
|
static ProximityKitManager |
getInstance(Context context,
KitConfig config)
Creates an instance of
ProximityKitManager . |
static ProximityKitManager |
getInstanceForApplication(Context context)
Deprecated.
As of 0.10.0, replaced by
ProximityKitManager.getInstance(Context, KitConfig) |
Kit |
getKit()
The local copy of the kit you have set up on ProximityKit.com
|
int |
getMaxRegionsBeforeRollup()
Deprecated.
As of release 0.5.0. This setting no longer does anything, as regions for
monitoring and ranging may now be explicitly configured on the ProximityKit server.
If you are using this roll up feature, please switch to configuring your ranging and
monitoring regions explicitly on the server.
Gets the maximum number of regions that may be individually configured in ProximityKit
before
the regions will start being automatically combined. This method has been deprecated and
the setting no longer has any effect.
|
ProximityKitGeofenceNotifier |
getProximityKitGeofenceNotifier()
Getter for the currently configured Geofence notification callback handler.
|
ProximityKitMonitorNotifier |
getProximityKitMonitorNotifier() |
ProximityKitRangeNotifier |
getProximityKitRangeNotifier() |
ProximityKitSyncNotifier |
getProximityKitSyncNotifier() |
void |
restart()
Deprecated.
As of 0.10.0, no replacement. To simply restart the manager use
ProximityKitManager.stop()
and ProximityKitManager.start() . To use a new configuration create a new manager using ProximityKitManager.getInstance(Context, KitConfig) . |
void |
setKit(Kit kit)
Used by the system when sync'ing data from the server.
|
void |
setMaxRegionsBeforeRollup(int regionCount)
Deprecated.
As of release 0.5.0. This setting no longer does anything, as regions for
monitoring and ranging may now be explicitly configured on the ProximityKit server.
If you are using this roll up feature, please switch to configuring your ranging and
monitoring regions explicitly on the server.
Sets the maximum number of regions that may be individually configured in ProximityKit
before
the regions will start being automatically combined. By default, each beacon or region in
the ProximityKit server results in one monitoring and ranging region. In cases of large
numbers of individual beacons configured on the server, these beacons will be combined into
a smaller number of matching regions for monitoring and ranging purposes.
By default, this value is -1, which means that no rollup will occur.
This method has been deprecated and the setting no longer has any effect.
|
void |
setPartnerIdentifier(String identifier)
Deprecated.
As of 0.10.0, replaced by
ProximityKitManager.getInstance(Context, KitConfig) |
void |
setProximityKitGeofenceNotifier(ProximityKitGeofenceNotifier notifier)
Register the Geofence notification callback handler.
|
void |
setProximityKitMonitorNotifier(ProximityKitMonitorNotifier notifier) |
void |
setProximityKitRangeNotifier(ProximityKitRangeNotifier notifier) |
void |
setProximityKitSyncNotifier(ProximityKitSyncNotifier notifier) |
void |
setSyncInterval(long milliseconds)
Sets the length of time, in milliseconds, between syncs with the Proximity Kit server.
|
void |
start()
Start syncing with the cloud and monitoring for various regions.
|
void |
stop()
Stop all Proximity Kit activities.
|
void |
sync()
Force a kit sync with the Proximity Kit cloud.
|
protected void |
syncIfNeeded()
Sync now but only if it is time
Not for public use.
This is used internally to attempt to sync on various device events.
|
protected Context context
@Deprecated protected ProximityKitManager()
ProximityKitManager.getInstance(Context,
KitConfig)
@Deprecated protected ProximityKitManager(Context context)
ProximityKitManager.getInstance(Context,
KitConfig)
ProximityKitManager
using the default properties file.
Not for public use.context
- An application Context
for the internal services and storage systems.IllegalStateException
- If the properties file cannot be found or loaded.MissingKeyException
- If properties file does not contain one or more required keys
.MissingValueException
- If properties file contains null
or an empty string for a required key
value.NullPointerException
- If context
is null
.NumberFormatException
- If the value set for KitConfig.CONFIG_SYNC_INTERVAL
in the properties
file cannot be parsed into a long
.public void disableGeofences()
public void enableGeofences() throws GooglePlayServicesException
GooglePlayServicesException
.GooglePlayServicesException
- It is the client's responsibility to ensure that Google Play services is properly
listed as a dependency, configured, is granted permission, and available on the device.
This exception is thrown under several conditions:
@Deprecated public static ProximityKitManager getInstanceForApplication(Context context)
ProximityKitManager.getInstance(Context, KitConfig)
ProximityKitManager
.
An accessor for the singleton instance of this class.
A Context
must be provided, but if you need to use it from a non-Activity or
non-Service class, you can attach it to another singleton or a subclass of the Android
Application
class.IllegalStateException
- If the properties file cannot be found or loaded.MissingKeyException
- If properties file does not contain one or more required keys
.MissingValueException
- If properties file contains null
or an empty string for a required key
value.NullPointerException
- If context
is null
.NumberFormatException
- If the value set for KitConfig.CONFIG_SYNC_INTERVAL
in the properties
file cannot be parsed into a long
.public static ProximityKitManager getInstance(Context context, KitConfig config)
ProximityKitManager
.
Sets up a stopped ProximityKitManager
with the provided configuration.
WARNING: this currently sets a singleton instance for the
application. Do NOT assume that this will always be the case. Calling
this method multiple times will overwrite the existing singleton instance. This may result
in unexecpted behavior if you externally store a reference to old instances. If the prior
instance is running configuring a new instance is not allowed and an IllegalStateException
is thrown. Until multiple instances are fully supported, we suggest
you implement your own ProximityKitManager
singleton in your application.context
- An application Context
for the internal services and storage systems.config
- The configuration settings for the manager.ProximityKitManager
configured according to config
and
associated with context
.IllegalStateException
- If an instance has already been initialized and is currently running.NullPointerException
- If appContext
or config
are null
.public BeaconManager getBeaconManager()
public static void debugOn()
public void start()
public void stop()
@Deprecated public void restart()
ProximityKitManager.stop()
and ProximityKitManager.start()
. To use a new configuration create a new manager using ProximityKitManager.getInstance(Context, KitConfig)
.ProximityKitManager
instance. But it also plumbs through license manager configuration changes throughout the
rest of the library.
You should not need to call this method. Use ProximityKitManager.stop()
and ProximityKitManager.start()
instead.
If you need a new configuration please create one instead using ProximityKitManager.getInstance(Context, KitConfig)
.public void sync()
KitConfig.CONFIG_SYNC_INTERVAL
protected void syncIfNeeded()
public ProximityKitGeofenceNotifier getProximityKitGeofenceNotifier()
ProximityKitGeofenceNotifier
or null
if
nothing has been configured.public void setProximityKitGeofenceNotifier(ProximityKitGeofenceNotifier notifier)
notifier
- The Geofence notification callback handlerpublic void setProximityKitMonitorNotifier(ProximityKitMonitorNotifier notifier)
public ProximityKitMonitorNotifier getProximityKitMonitorNotifier()
public void setProximityKitRangeNotifier(ProximityKitRangeNotifier notifier)
public ProximityKitRangeNotifier getProximityKitRangeNotifier()
public void setProximityKitSyncNotifier(ProximityKitSyncNotifier notifier)
public ProximityKitSyncNotifier getProximityKitSyncNotifier()
public Kit getKit()
public void setKit(Kit kit)
public com.radiusnetworks.proximity.proximitykit.BeaconAdapter getBeaconAdapter()
@Deprecated public void setPartnerIdentifier(String identifier)
ProximityKitManager.getInstance(Context, KitConfig)
identifier
- @Deprecated public void clearPartnerIdentifier()
ProximityKitManager.getInstance(Context, KitConfig)
public void setSyncInterval(long milliseconds)
KitConfig
instead.
This does not change the value of the manager's base KitConfig
. Instead it updates
the current interval. This will be reset on the next app start.
Note that syncing does tax battery life as well as consume network bandwidth, so we do not
recommend setting this to a low value.
The minimum value is 300000L ms.milliseconds
- Length of time, in milliseconds, between syncs with the Proximity Kit server.KitConfig.CONFIG_SYNC_INTERVAL
@Deprecated public void setMaxRegionsBeforeRollup(int regionCount)
regionCount
- @Deprecated public int getMaxRegionsBeforeRollup()
ProximityKitManager.setMaxRegionsBeforeRollup(int)