Skip to main content
Version: Eyedid Beta

Quick Start (Java)

Supported Environment

  • Minimum supported Android API level is 23

  • Target Android API level is 34

  • Camera permission, Network permission and Network connected environment are required.

  • Build target to REAL DEVICE during the development process.

info

Eyedid SDK uses the front camera of the device.

Installation

1. First, add the following to the repositories section of your project’s root build.gradle or build.gradle.kts file:

  allprojects {
repositories {
google()
mavenCentral()
// Add the Eyedid SDK Maven repository
maven {
url = uri("https://seeso.jfrog.io/artifactory/visualcamp-eyedid-sdk-android-release")
}
}
}

2. Add the Eyedid SDK Dependency

Next, in the build.gradle or build.gradle.kts file of the module where you want to use the Eyedid SDK, add the following line to the dependencies section:

dependencies {
// Add the Eyedid Gaze Tracker dependency
implementation "camp.visual.eyedid.android.gazetracker:eyedid-gazetracker:{version}"
}

Using the Eyedid SDK

1. The camera permission needs to be set in the app's manifest.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourapp">
<!-- Add Camera permission -->
<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!-- Other activities and services -->

</application>

</manifest>

2. Since camera permission is required at runtime, you should obtain the camera permission before using the Eyedid SDK.

  • The following is a simple example of getting the camera permission. The code will call permissionGranted when the permission is authorized.
public class MainActivity extends AppCompatActivity { 
private static final String[] PERMISSIONS = new String[]
{ Manifest.permission.CAMERA };
private static final int REQ_PERMISSION = 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPermission();
// Your other initialization code...
}

private void checkPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check permission status
if (!hasPermissions(PERMISSIONS)) {
requestPermissions(PERMISSIONS, REQ_PERMISSION);
} else {
checkPermission(true);
}
} else {
checkPermission(true);
}
}

@RequiresApi(Build.VERSION_CODES.M)
private boolean hasPermissions(String[] permissions) {
int result;
// Check permission status in string array
for (String perms : permissions) {
if (perms.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
if (!Settings.canDrawOverlays(this)) {
return false;
}
}
result = ContextCompat.checkSelfPermission(this, perms);
if (result == PackageManager.PERMISSION_DENIED) {
// When unauthorized permission found
return false;
}
}
// When all permissions are allowed
return true;
}

private void checkPermission(boolean isGranted) {
if (isGranted) {
permissionGranted();
} else {
finish();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQ_PERMISSION:
if (grantResults.length > 0) {
boolean cameraPermissionAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (cameraPermissionAccepted) {
checkPermission(true);
} else {
checkPermission(false);
}
}
break;
}
}

// This method is called when camera permission is granted
private void permissionGranted() {
// Initialize your SDK or start your camera-related functionality here
}
}

3. GazeTracker Initialization

  • This is an example that initializes GazeTracker.
tip

Please enter a valid licenseKey to initialize GazeTracker.

  ...

GazeTracker gazeTracker = null;

...

private void permissionGranted() {
initGaze();
}

private void initGaze() {
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";

GazeTrackerOptions options = new GazeTrackerOptions.Builder().build();

GazeTracker.initGazeTracker(getApplicationContext(), licenseKey, initializationCallback, options);
}

private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};

private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
}

private void initFail(InitializationErrorType error) {
String err;
if (error == InitializationErrorType.ERROR_INIT) {
// When initialization fails
err = "Initialization failed";
} else if (error == InitializationErrorType.ERROR_CAMERA_PERMISSION) {
// When camera permission does not exist
err = "Required permission not granted";
} else {
// Eyedid SDK initialization failure
// This can be caused by several reasons (e.g., Out of memory).
err = "Eyedid SDK initialization failed";
}
Log.w("Eyedid SDK", "Error description: " + err);
}
...

4. Register Callbacks

  • You can register callbacks that you want to trigger when GazeTracker is successfully initialized. The TrackingCallback is a callback interface that provides gaze point data and other related metrics.
private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
// Register the tracking callback to receive gaze data
this.gazeTracker.setTrackingCallback(trackingCallback);
}

private final TrackingCallback trackingCallback = new TrackingCallback() {
@Override
public void onMetrics(long timestamp, GazeInfo gazeInfo, FaceInfo faceInfo, BlinkInfo blinkInfo, UserStatusInfo userStatusInfo) {
Log.i("Eyedid SDK", "Gaze coordinates: " + gazeInfo.x + "x" + gazeInfo.y);
}

@Override
public void onDrop(long timestamp) {

}
};

5. Run startTracking() to start Gaze Tracking.

  this.gazeTracker.startTracking();

Advanced Features and Further Customization

For more advanced features like calibration, blink detection, or saving gaze data, please refer to our API Documentation. There you’ll find detailed information on how to fully utilize the Eyedid SDK's capabilities.