Client to Server
For this integration method, the DeviceAssure library collects device data and automatically sends it to the DeviceAssure API for validation. Results are returned directly to your application via callbacks.
This is the recommended approach as it automatically uses the nearest DeviceAssure service endpoint for optimal response time.
Note: A valid licence key is required for Client to Server integration.
Overview
There are three main steps to validate a device:
- Initialize the DeviceAssure library with the application context
- Call the
check()method with your licence key and callback handler - Handle the validation results returned via the callback
Implementation
Step 1: Initialize the Library
Initialize DeviceAssure in your Application class's onCreate() method:
import android.app.Application;
import com.deviceassure.android.library.networking.DeviceAssure;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
DeviceAssure.init(this.getApplicationContext());
}
}
Step 2: Define the Callback Interface
Create a delegate interface to handle responses:
import org.json.JSONObject;
public interface DeviceAssureDelegate {
void onResponse(JSONObject json);
void onError(String error);
}
Step 3: Create a Callback Handler
import org.json.JSONObject;
import com.deviceassure.android.library.networking.Callback;
public class DeviceAssureCallback implements Callback {
private DeviceAssureDelegate delegate;
public DeviceAssureCallback(DeviceAssureDelegate delegate) {
this.delegate = delegate;
}
@Override
public void taskComplete(JSONObject result) {
delegate.onResponse(result);
}
@Override
public void handleError(String errorStr) {
delegate.onError(errorStr);
}
@Override
public void progressUpdate(Integer percent) {
// Track progress if needed
}
}
Step 4: Perform Validation
Call the check() method from anywhere in your application:
Complete Example
import android.app.Application;
import android.util.Log;
import org.json.JSONObject;
import com.deviceassure.android.library.networking.DeviceAssure;
public class MyApplication extends Application implements DeviceAssureDelegate {
private static final String TAG = "DeviceAssure";
@Override
public void onCreate() {
super.onCreate();
// Initialize the library
DeviceAssure.init(this.getApplicationContext());
// Perform validation
DeviceAssure.check("<LICENCE_KEY>", new DeviceAssureCallback(this));
}
@Override
public void onResponse(JSONObject json) {
Log.d(TAG, "Validation result: " + json.toString());
// Check the "result" field for AUTHENTIC, NON-AUTHENTIC, etc.
}
@Override
public void onError(String error) {
Log.e(TAG, "Validation error: " + error);
}
}
When to Call Validation
The check() method can be called from anywhere in the application, but it is recommended to call it:
- On application install
- On application create (
onCreate())
Exception: If certain permissions are required before calling the library (e.g., to allow collection of the TAC), wait until those permissions are granted.
Performance Notes
- The library uses a background thread to avoid blocking the main UI thread
- If background processing doesn't complete within 10 seconds, it terminates and returns data collected up to that point
- For best results, request necessary permissions before calling validation
See Also
- Server to Server - Validate via your backend server instead
- How It Works - Client to Server and Server to Server models
- API Responses - Understanding validation results and classifications