Basic Integration
Once you have installed the library, you can integrate DeviceAssure into your Android application.
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: 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 org.json.JSONObject;
import com.deviceassure.android.library.networking.DeviceAssure;
import com.deviceassure.android.library.networking.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: For accurate validation, ensure the required permissions are granted before calling
check(). See Add the Library for permission 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
- Server to Server - Validation via your backend server
- API Responses - Understanding validation results and classifications