Basic Integration
Once you have installed the library, you can integrate DeviceAssure into your Android application. If you resolved the library from Maven, its runtime dependencies are already on your application's classpath; if you added it as a raw .aar, add them yourself first or the first call below fails at runtime.
The library is written in Kotlin, and the callback API shown here is usable from both Kotlin and Java. Each example below is shown in both languages.
Step 1: Initialize the Library
Initialize DeviceAssure in your Application class's onCreate() method:
Step 2: Perform Validation
Call the check() method to validate the device. This example shows a minimal implementation:
import android.app.Application
import android.util.Log
import com.deviceassure.android.library.Callback
import com.deviceassure.android.library.DeviceAssure
import org.json.JSONObject
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize DeviceAssure
DeviceAssure.init(applicationContext)
// Perform validation
DeviceAssure.check("<LICENCE_KEY>", object : Callback {
override fun taskComplete(result: JSONObject) {
Log.d(TAG, "Validation result: $result")
// Check the "result" field for AUTHENTIC, NON-AUTHENTIC, etc.
}
override fun handleError(errorStr: String) {
Log.e(TAG, "Validation error: $errorStr")
}
override fun progressUpdate(percent: Int?) {
// Track progress if needed
}
})
}
companion object {
private const val TAG = "DeviceAssure"
}
}
import android.app.Application;
import android.util.Log;
import org.json.JSONObject;
import com.deviceassure.android.library.DeviceAssure;
import com.deviceassure.android.library.Callback;
public class MyApplication extends Application {
private static final String TAG = "DeviceAssure";
@Override
public void onCreate() {
super.onCreate();
// Initialize DeviceAssure
DeviceAssure.init(this.getApplicationContext());
// Perform validation
DeviceAssure.check("<LICENCE_KEY>", new Callback() {
@Override
public void taskComplete(JSONObject result) {
Log.d(TAG, "Validation result: " + result.toString());
// Check the "result" field for AUTHENTIC, NON-AUTHENTIC, etc.
}
@Override
public void handleError(String error) {
Log.e(TAG, "Validation error: " + error);
}
@Override
public void progressUpdate(Integer percent) {
// Track progress if needed
}
});
}
}
Note:
Callbackrequires three methods:taskComplete(),handleError()andprogressUpdate(). It also declares two deprecated hooks,statusUpdate()and a no-argumenttaskComplete(), which the library never calls and which do not need to be implemented.Note: The library does not request permissions itself. For accurate validation, your application must request and be granted the required permissions before calling
check(). See Add the Library for details.
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
For more advanced integration options, see:
- Client to Server - Detailed C2S implementation with callback patterns, and the suspending API for Kotlin
- Server to Server - Validation via your backend server
- API Responses - Understanding validation results and classifications