Class WPS
- java.lang.Object
-
- com.skyhookwireless.wps.WPSExtra
-
- com.skyhookwireless.wps.WPS
-
-
Constructor Summary
Constructors Constructor Description WPS(android.content.Context context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
abort()
Attempts to immediately cancel any operations that are executing in the background, before returning.WPSReturnCode
cancelAllGeoFences()
Cancel all geofences.WPSReturnCode
cancelGeoFence(WPSGeoFence.Handle handle)
Cancel a geofence.void
destroy()
void
enableCalibration(boolean enable)
void
getCertifiedLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, WPSCertifiedLocationCallback callback)
Requests certified geographic location updates.void
getIPLocation(WPSAuthentication authentication, WPSStreetAddressLookup addressLookup, boolean timeZoneLookup, IPLocationCallback callback)
Request geographic location information based on the IP address of the client making the request.void
getIPLocation(WPSAuthentication authentication, WPSStreetAddressLookup addressLookup, IPLocationCallback callback)
Request geographic location information based on the IP address of the client making the request.void
getLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, boolean timeZoneLookup, WPSLocationCallback callback)
Requests geographic location.void
getLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, WPSLocationCallback callback)
Requests geographic location.void
getOfflineLocation(WPSAuthentication authentication, byte[] key, byte[] token, WPSLocationCallback callback)
Requests geographic location based on a token collected at a different time.byte[]
getOfflineToken(WPSAuthentication authentication, byte[] key)
Retrieve an offline token based on the latest observed Wi-Fi access points and cell towers.void
getPeriodicLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, boolean timeZoneLookup, long period, int iterations, WPSPeriodicLocationCallback callback)
Requests periodic geographic location.void
getPeriodicLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, long period, int iterations, WPSPeriodicLocationCallback callback)
Requests periodic geographic location.static java.lang.String
getVersion()
Get the SDK version.void
injectLocation(WPSLocation userLocation)
Deprecated.Not supported in this releasevoid
registerUser(WPSAuthentication authentication, WPSAuthentication newAuth, RegistrationCallback callback)
Register a new user.void
renewAuthentication()
Deprecated.Not supported in this releasevoid
resetCalibration()
void
setAuthentication(java.lang.String key, java.lang.String sku)
Set the user's authentication information.WPSGeoFence.Handle
setGeoFence(WPSGeoFence geofence, GeoFenceCallback callback)
Define a new geofence.void
setKey(java.lang.String key)
Set the user's API key.void
setLocalFilePaths(java.util.List<java.lang.String> paths)
Set the path to local files so location determination can be performed locally.static void
setProxy(java.lang.String address, int port, java.lang.String username, java.lang.String password)
Set up a proxy server.void
setRegistrationUser(WPSAuthentication authentication)
Set the user's authentication information.static void
setServerUrl(java.lang.String url)
Overwrite the server's url from its default value.void
setTiling(java.lang.String dirpath, long maxDataSizePerSession, long maxDataSizeTotal, TilingListener listener)
Setup tiling so location determination can be performed locally.void
tuneLocation(WPSAuthentication authentication, WPSLocation newLocation, TuneLocationCallback callback)
Tune the last location returned.
-
-
-
Method Detail
-
setServerUrl
public static void setServerUrl(java.lang.String url)
Overwrite the server's url from its default value.- Parameters:
url
- the url to the server. A value ofnull
turns off remote determination of location.
-
setProxy
public static void setProxy(java.lang.String address, int port, java.lang.String username, java.lang.String password)
Set up a proxy server.- Parameters:
address
- the internet address of the proxy server.port
- the TCP port number of the proxy server.username
- the username to authenticate with the proxy server. Can be set tonull
for un-authenticated proxy servers.password
- the password for authentication with the proxy server. Can be set tonull
for un-authenticated proxy servers.
-
getVersion
public static java.lang.String getVersion()
Get the SDK version.- Returns:
- a string containing the version information as
<major>.<minor>.<revision>.<build>
-
abort
public void abort()
Description copied from interface:IWPS
Attempts to immediately cancel any operations that are executing in the background, before returning.
-
getIPLocation
public void getIPLocation(WPSAuthentication authentication, WPSStreetAddressLookup addressLookup, IPLocationCallback callback)
Description copied from interface:IWPS
Request geographic location information based on the IP address of the client making the request.- Specified by:
getIPLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.addressLookup
- the street address lookup type desired.callback
- anIPLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getIPLocation
public void getIPLocation(WPSAuthentication authentication, WPSStreetAddressLookup addressLookup, boolean timeZoneLookup, IPLocationCallback callback)
Description copied from interface:IWPS
Request geographic location information based on the IP address of the client making the request.- Specified by:
getIPLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.addressLookup
- the street address lookup type desired.timeZoneLookup
- request timezone lookup in addition to latitude/longitude lookup.callback
- anIPLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getLocation
public void getLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, WPSLocationCallback callback)
Description copied from interface:IWPS
Requests geographic location.- Specified by:
getLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.streetAddressLookup
- request street address lookup in addition to latitude/longitude lookup.callback
- aWPSLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getLocation
public void getLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, boolean timeZoneLookup, WPSLocationCallback callback)
Description copied from interface:IWPS
Requests geographic location.- Specified by:
getLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.streetAddressLookup
- request street address lookup in addition to latitude/longitude lookup.timeZoneLookup
- request timezone lookup in addition to latitude/longitude lookup.callback
- aWPSLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getPeriodicLocation
public void getPeriodicLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, long period, int iterations, WPSPeriodicLocationCallback callback)
Description copied from interface:IWPS
Requests periodic geographic location.- Specified by:
getPeriodicLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.streetAddressLookup
- request street address lookup in addition to latitude/longitude lookup. Note that street address lookup is only performed when the location is determined by the remote server (network-centric model), not when the location is determined locally.period
- maximum time in milliseconds between location reports.
WPS will invoke the callback at least every period, either with a location update or with an error if no location can be determined. WPS may report location updates more often than the specified period if a new or better location becomes available within a given period.
This parameter is also used to specify the preferred Wi-Fi scan period, which WPS may override for optimal performance and power savings.iterations
- number of time a location is to be reported. A value of zero indicates an unlimited number of iterations.callback
- aWPSPeriodicLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getPeriodicLocation
public void getPeriodicLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, boolean timeZoneLookup, long period, int iterations, WPSPeriodicLocationCallback callback)
Description copied from interface:IWPS
Requests periodic geographic location.- Specified by:
getPeriodicLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.streetAddressLookup
- request street address lookup in addition to latitude/longitude lookup. Note that specifying a street address lookup will enforce locations to be determined by the remote server (network-centric model).timeZoneLookup
- request timezone lookup in addition to latitude/longitude lookup. Note that specifying a time zone lookup will enforce locations to be determined by the remote server (network-centric model).period
- maximum time in milliseconds between location reports.
WPS will invoke the callback at least every period, either with a location update or with an error if no location can be determined. WPS may report location updates more often than the specified period if a new or better location becomes available within a given period.
This parameter is also used to specify the preferred Wi-Fi scan period, which WPS may override for optimal performance and power savings.iterations
- number of time a location is to be reported. A value of zero indicates an unlimited number of iterations.
Using this parameter to set a finite number of iterations is not recommended for new applications. The preferred way to bound the duration of the location request is to explicitly interrupt it by returningWPSContinuation.WPS_STOP
or invokingIWPS.abort()
.callback
- aWPSPeriodicLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getCertifiedLocation
public void getCertifiedLocation(WPSAuthentication authentication, WPSStreetAddressLookup streetAddressLookup, WPSCertifiedLocationCallback callback)
Description copied from interface:IWPS
Requests certified geographic location updates. To stop receiving updates, either returnWPSContinuation.WPS_STOP
from the callback, or invokeabort()
.- Specified by:
getCertifiedLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.streetAddressLookup
- request street address lookup in addition to latitude/longitude lookup.callback
- aWPSCertifiedLocationCallback
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location
-
getOfflineToken
public byte[] getOfflineToken(WPSAuthentication authentication, byte[] key)
Description copied from interface:IWPS
Retrieve an offline token based on the latest observed Wi-Fi access points and cell towers. This token can be saved and converted to a location later by callinggetOfflineLocation
.A sensible time to call
getOfflineToken
is from eithergetLocation
orgetPeriodicLocation
callback with aWPS_ERROR_SERVER_UNAVAILABLE
error code (indicating the device is offline).Offline tokens are only valid for 90 days after they are generated. Attempting to redeem a token more than 90 days old will result in an error.
Sample Code:
final byte[] token = _wps.getOfflineToken(null, null); if (token == null) { System.err.println("no token to save"); } else { // save the token in persistent storage // ... }
- Specified by:
getOfflineToken
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.key
- deprecated and must be set tonull
- Returns:
- the offline token or null if XPS does not have enough information to be able to determine a location later.
- Throws:
java.lang.SecurityException
- if caller does not have permission to access location- See Also:
IWPS.getOfflineLocation(WPSAuthentication, byte[], byte[], WPSLocationCallback)
-
getOfflineLocation
public void getOfflineLocation(WPSAuthentication authentication, byte[] key, byte[] token, WPSLocationCallback callback)
Description copied from interface:IWPS
Requests geographic location based on a token collected at a different time.This method may be called while a getLocation or getPeriodicLocation call is in progress. If it is called while another getOfflineLocation call is already in progress, then that one will be aborted.
Offline tokens are only valid for 90 days after they are generated. Attempting to redeem a token more than 90 days old will result in an error.
Although a token can be collected when a location has been calculated
getOfflineLocation
is not guaranteed to return a location with that same token.Sample Code:
// restore token stored earlier final byte[] token = ... ; _wps.getOfflineLocation(null, null, token, new WPSLocationCallback() { public void handleWPSLocation(final WPSLocation location) { // use the location // ... } public WPSContinuation handleError(final WPSReturnCode error) { System.err.println("getOfflineLocation() failed: "+error); // ... return WPSContinuation.WPS_STOP; } public void done() { //... } });
- Specified by:
getOfflineLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.key
- deprecated and must be set tonull
token
- the token to be converted to a location.callback
- aWPSLocationCallback
.- See Also:
IWPS.getOfflineToken(WPSAuthentication, byte[])
-
setKey
public void setKey(java.lang.String key)
Description copied from interface:IWPS
Set the user's API key.Make sure to call this method before making any other calls, such as during initialization of the application.
After this call you should pass
null
asauthentication
to other calls likegetLocation
.Must not be used in conjunction with
IWPS.setAuthentication(java.lang.String, java.lang.String)
.
-
setAuthentication
public void setAuthentication(java.lang.String key, java.lang.String sku)
Description copied from interface:IWPS
Set the user's authentication information.Make sure to call this method before making any other calls, such as during initialization of the application.
After this call you should pass
null
asauthentication
to other calls likegetLocation
.Must not be used in conjunction with
IWPS.setKey(java.lang.String)
.- Specified by:
setAuthentication
in interfaceIWPS
- Parameters:
key
- an existing user's API key.sku
- product's SKU.
-
renewAuthentication
@Deprecated public void renewAuthentication()
Deprecated.Not supported in this release- Specified by:
renewAuthentication
in classcom.skyhookwireless.wps.WPSExtra
-
enableCalibration
public void enableCalibration(boolean enable)
- Specified by:
enableCalibration
in classcom.skyhookwireless.wps.WPSExtra
-
resetCalibration
public void resetCalibration()
- Specified by:
resetCalibration
in classcom.skyhookwireless.wps.WPSExtra
-
setRegistrationUser
public void setRegistrationUser(WPSAuthentication authentication)
Description copied from interface:IWPS
Set the user's authentication information.Make sure to call this method before making any other calls, such as during initialization of the application.
After this call you should pass
null
asauthentication
to other calls likegetLocation
.Must not be used in conjunction with
IWPS.setKey(java.lang.String)
.- Specified by:
setRegistrationUser
in interfaceIWPS
- Parameters:
authentication
- an existing user's authentication information.
-
registerUser
public void registerUser(WPSAuthentication authentication, WPSAuthentication newAuth, RegistrationCallback callback)
Description copied from interface:IWPS
Register a new user.New applications are encouraged to simply use the auto-registration feature by calling registerUser, such as during initialization of the application.
For example:// Info from Skyhook private static final String WPS_USERNAME = "myusername"; private static final String WPS_REALM = "myrealm"; private final WPSAuthentication _wpsUser = new WPSAuthentication(WPS_USERNAME, WPS_REALM); void wpsInit() { _wps.registerUser(_wpsUser, null, new RegistrationCallback() { public void handleSuccess() { // ... } public WPSContinuation handleError(final WPSReturnCode error) { // ... return WPSContinuation.WPS_CONTINUE; } public void done() { //... } }); }
Applications that still want to control how usernames are generated can continue to do so as they did before since version 4.2 is backward compatible with 4.1. For example:// Info from Skyhook private static final String WPS_USERNAME = "myusername"; private static final String WPS_REALM = "myrealm"; // Where generateUsername() returns your own generated username private final WPSAuthentication _wpsUser = new WPSAuthentication(generateUsername(), WPS_REALM); void wpsInit() { // Where readUsername() returns the saved username, or null if // there isn't one saved if (_wpsUser.getUsername().equals(readUsername())) { // user already registered (and matched generated username) return; } _wps.registerUser(new WPSAuthentication(WPS_USERNAME, WPS_REALM), _wpsUser, new RegistrationCallback() { public void handleSuccess() { // ... saveUsername(_wpsUser.getUsername()); } public WPSContinuation handleError(final WPSReturnCode error) { // ... return WPSContinuation.WPS_CONTINUE; } public void done() { //... } }); }
Note that the generated username should be stable -- ie. remain constant over time, every time it is generated -- to avoid unnecessary re-registrations. Care should be taken when generating a username to protect the privacy of the user, and should not contain any personally identifiable information.
Now whenever your application needs to determine a location, it can simply call getLocation() or getPeriodicLocation(), even if registerUser() is still ongoing, or if it has failed. For example:_wps.getLocation(_wpsUser, WPSStreetAddressLookup.WPS_FULL_STREET_ADDRESS_LOOKUP new WPSLocationCallback() {...});
- Specified by:
registerUser
in interfaceIWPS
- Parameters:
authentication
- an existing user's authentication information.newAuth
- the new user's authentication information or null to trigger auto-registration.callback
- aRegistrationCallback
-
tuneLocation
public void tuneLocation(WPSAuthentication authentication, WPSLocation newLocation, TuneLocationCallback callback)
Description copied from interface:IWPS
Tune the last location returned. The device must be at the location specified innewLocation
during the entire duration of this call. Note that pure GPS locations will not reflect any tuning.Tuning is not an effective strategy for trying to make small adjustments to a location. It is best used for adding to our coverage or fixing results that are off by hundreds of meters.
- Specified by:
tuneLocation
in interfaceIWPS
- Parameters:
authentication
- must benull
for new applications that useIWPS.setKey(java.lang.String)
orIWPS.setAuthentication(java.lang.String, java.lang.String)
, otherwise set to the user's authentication information.newLocation
- the tuned locationcallback
- aTuneLocationCallback
-
setLocalFilePaths
public void setLocalFilePaths(java.util.List<java.lang.String> paths)
Description copied from interface:IWPS
Set the path to local files so location determination can be performed locally.- Specified by:
setLocalFilePaths
in interfaceIWPS
- Parameters:
paths
- a list of compressed positioning data file paths. This list replaces all previous values. Usenull
to clear and release local files.
-
setTiling
public void setTiling(java.lang.String dirpath, long maxDataSizePerSession, long maxDataSizeTotal, TilingListener listener)
Description copied from interface:IWPS
Setup tiling so location determination can be performed locally. Tiles are typically less then 50KB in size, so to download an area of 3x3 tiles for each session you would setmaxDataSizePerSession
to 450KB, i.e. 460,800. It is recommended thatmaxDataSizePerSession
be a factor of 2 - 10 smaller thanmaxDataSizeTotal
, so that tiles from several areas can be cached.- Specified by:
setTiling
in interfaceIWPS
- Parameters:
dirpath
- the path to a directory to store tiles.maxDataSizePerSession
- the maximum size of data downloaded per session, in bytes. A value of 0 disables any further tile downloads.maxDataSizeTotal
- the maximum size of all stored tiles, in bytes. A value of 0 causes all stored tiles to be deleted.listener
- the callback function to control the tile download. By default, all tiles are downloaded.
-
setGeoFence
public WPSGeoFence.Handle setGeoFence(WPSGeoFence geofence, GeoFenceCallback callback)
Description copied from interface:IWPS
Define a new geofence.Sample Code:
final WPSGeoFence geofence = new WPSGeoFence(42.1234, -71.5678, 100, WPSGeoFence.Type.WPS_GEOFENCE_ENTER, 0); final WPSGeoFence.Handle handle = _wps.setGeoFence(geofence, new MyGeoFenceCallback()); if (handle == null) System.err.println("setGeoFence() failed"); _wps.getPeriodicLocation(null, WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP, 60 * 60 * 1000, 0, new MyPeriodicLocationCallback());
- Specified by:
setGeoFence
in interfaceIWPS
- Parameters:
geofence
- the geofence to monitorcallback
- theGeoFenceCallback
to invoke when this geofence is triggered- Returns:
- a
WPSGeoFence.Handle
that can be used to cancel geofence or null if geofence cannot be registered. - Throws:
java.lang.SecurityException
- if caller does not have permission to access location- See Also:
IWPS.cancelGeoFence(WPSGeoFence.Handle)
-
cancelGeoFence
public WPSReturnCode cancelGeoFence(WPSGeoFence.Handle handle)
Description copied from interface:IWPS
Cancel a geofence.- Specified by:
cancelGeoFence
in interfaceIWPS
- Parameters:
handle
- of geofence to cancel- Returns:
- a
WPSReturnCode
.
WPS_GEOFENCE_ERROR
indicates the geofence for this handle isn't defined. - See Also:
IWPS.setGeoFence(WPSGeoFence, GeoFenceCallback)
-
cancelAllGeoFences
public WPSReturnCode cancelAllGeoFences()
Description copied from interface:IWPS
Cancel all geofences.- Specified by:
cancelAllGeoFences
in interfaceIWPS
- Returns:
- a
WPSReturnCode
- See Also:
IWPS.setGeoFence(WPSGeoFence, GeoFenceCallback)
-
injectLocation
@Deprecated public void injectLocation(WPSLocation userLocation)
Deprecated.Not supported in this release- Specified by:
injectLocation
in classcom.skyhookwireless.wps.WPSExtra
-
-