The Quick Start project illustrates minimal steps to integrate the SDK into your app.
Contact support.tps@qti.qualcomm.com to request access to the SDK and get the API key.
Put the SDK library file under the app/libs/
subdirectory and add it to the dependencies
section of your build.gradle
:
dependencies {
implementation files('libs/wpsapi.aar')
}
Import the Skyhook WPS package:
import com.skyhookwireless.wps;
Create a new instance of the XPS
class in the onCreate
method of your activity or application class and set your API key:
private IWPS xps;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
xps = new XPS(this);
xps.setKey("YOUR KEY");
...
}
Make sure to replace "YOUR KEY"
with your real API key in the Quick Start app source code (see the onCreate()
method in MainActivity.java
).
In order to be able to start location determination, your app must first obtain the ACCESS_FINE_LOCATION
permission from the user:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ActivityCompat.requestPermissions(
this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
}
Once the location permission has been granted, you can make a locaton request.
Note that the callback methods are invoked from the background thread, so you have to use runOnUiThread()
to manipulate the UI.
xps.getLocation(null, WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP, false, new WPSLocationCallback() {
@Override
public void handleWPSLocation(WPSLocation location) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// display location
}
});
}
@Override
public WPSContinuation handleError(WPSReturnCode error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// display error
}
});
return WPSContinuation.WPS_CONTINUE;
}
@Override
public void done() {
// after done() returns, you can make more XPS calls
}
});
Note: starting with Android 9 a fresh Wi-Fi location can only be calculated four times during a 2-minute period.
Please refer to the full SDK guide for more information.
Copyright (c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
This work is licensed under the CC BY-ND 4.0 License. See LICENSE for more details.