Using the Android Emulator
The SDK will not provide wifi or cellular location from the emulator because it is unable to scan for wifi or cellular signals. In order to verify your integration of the SDK using the emulator, you may want to use the getIPLocation() method call. The other location methods will only return location fixes on an Android device
Include the Library Files
The library files are found in the libs directory of the SDK. Add all files into the libs directory of your project.
Android Manifest
You'll need to add the following permissions to your AndroidManifest.xml:
<!-- used to communicate with Skyhook's servers -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- enables WiFi, if disabled, for the duration of a location request -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- used to obtain information about the WiFi environment -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- required by our basic location algorithm -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /> />
Import Skyhook Classes
import com.skyhookwireless.wps.*;
User Registration
Set Registration User
Before you can make location calls, your app must configure its registration account. Please see our documentation for more information on user registration
setRegistrationUser should be called every time your application launches. In your application, the call would look like this:
// Create the authentication object
// myAndroidContext must be a Context instance
XPS _xps = new XPS(myAndroidContext);
WPSAuthentication auth = new WPSAuthentication("myUsername", "myRealm");
_xps.setRegistrationUser(auth);
XPS Location Call
One-Time Location Request
The one-time location request provides a method to make a single request for location. The request will call the callback method. The WPSLocationCallback class has three methods, done(), handleError() and handleWPSLocation(). The handleWPSLocation() method is passed the WPSLocation object which will contain the location information.
A one-time location request call from your application would look like this:
// Callback object
WPSLocationCallback callback = new WPSLocationCallback()
{
// What the application should do after it's done
public void done()
{
// after done() returns, you can make more WPS calls.
}
// What the application should do if an error occurs
public WPSContinuation handleError(WPSReturnCode error)
{
handleWPSError(error); // you'll implement handleWPSError()
// To retry the location call on error use WPS_CONTINUE,
// otherwise return WPS_STOP
return WPSContinuation.WPS_STOP;
}
// Implements the actions using the location object
public void handleWPSLocation(WPSLocation location)
{
// you'll implement printLocation()
printLocation(location.getLatitude(), location.getLongitude());
}
};
// Call the location function with callback.
// Note: You should use the same XPS object that made the setRegistrationUser call,
// and set the first parameter to null unless you are relying on old registration. If using old registration, the first parameter should be set to the auth object constructed using your registration user credential.
_xps.getLocation(null,
WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP,
callback);For a more detailed code sample, you may view the example code included in the example directory of the SDK download.
For more detailed documentation, view the javadoc in the documentation directory of the SDK download.
Troubleshooting
For any questions, please visit the developer forum at: