DeviceAnalyser (Deprecated)

Get relevant information from an Android device.

The Device Analyser is capable of obtaining highly accurate geolocation data.

Runtime permissions

PermissionReasonRequired

ACCESS_COARSE_LOCATION

To get the approximate location

Yes.

ACCESS_FINE_LOCATION

To get the exact location

Yes.

Instantiating the SDK

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();

Builder method

ParameterRequired

AppCompatActivity activity

Your activity, to set the context of the application

Yes

.setPriority(int priority)

Sets the priority of accuracy, which can be:

  • RIORITY_HIGH_ACCURACY

  • PRIORITY_BALANCED_POWER_ACCURACY

  • PRIORITY_LOW_POWER

  • PRIORITY_NO_POWER

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.

LocationInfo

MethodData 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

LocationListener

ResultData Type

.onSuccess(LocationInfo locationInfo)

On success, returns a LocationInfo object with the geolocation data:

  • .isUsingFakeGPS()

  • .getLatitude()

  • .getLongitude()

  • .getAccuracy()

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
    }
};

Example of use

deviceAnalyser = new DeviceAnalyser.Builder(this).build();
deviceAnalyser.getLocation(locationListener);

onActivityResult

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 updated

Logo

2023 © Caf. - All rights reserved