DeviceAnalyser
Get relevant information from an Android device.
The Device Analyser is capable of obtaining highly accurate geolocation data.
Permission | Reason | Required |
---|---|---|
ACCESS_COARSE_LOCATION | To get the approximate location | Yes. |
ACCESS_FINE_LOCATION | To get the exact location | Yes. |
First, create an object of type
DeviceAnalyser
. This object is for you to configure all your business rules for the SDK:DeviceAnalyser mDeviceAnalyser = new DeviceAnalyser.Builder(@NonNull AppCompatActivity activity)
// see table allow
.build();
Parameter | Required |
---|---|
AppCompatActivity activity Your activity, to set the context of the application | Yes |
.setPriority(int priority) Sets the priority of accuracy, which can be:
Priorities are available in the Constants class, e.g.: .setPriority(Constants.PRIORITY_HIGH_ACCURACY) | No, by default it is PRIORITY_BALANCED_POWER_ACCURACY |
.getLocation(LocationListener listener) Returns the geolocation information if available, otherwise returns a sdkFailure. Expects a locationListener as an argument, as explained in this example. | Yes. |
Method | Data Type |
---|---|
.isUsingFakeGPS() Returns whether the device is using a dummy/fake location | boolean |
.getLatitude() Returns the latitude information | double |
.getLongitude() Returns the longitude information | double |
.getAccuracy() Returns the accuracy of the information obtained | float |
Result | Data Type |
---|---|
.onSuccess(LocationInfo locationInfo)
| LocationInfo |
.onFailure(Failure sdkFailure) On failure, returns a sdkFailure | Failure |
LocationListener locationListener = new LocationListener() {
@Override
public void onSuccess(LocationInfo locationInfo) {
//Success
}
@Override
public void onFailure(Failure sdkFailure) {
//Fail
}
};
deviceAnalyser = new DeviceAnalyser.Builder(this).build();
deviceAnalyser.getLocation(locationListener);
Use the
onActivityResult
method to get the result of the user's interaction with the GPS activation request popup on the device:@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.REQUEST_CODE_OF_GPS_DIALOG) {
switch (resultCode) {
case Activity.RESULT_OK:
// Make a new call to the getLocation() method in case the user has activated GPS
deviceAnalyser.getLocation(locationListener);
break;
case Activity.RESULT_CANCELED:
// User refused GPS activation
break;
default:
break;
}
}
}
Last modified 5mo ago