Introduction and requirements
The E4 link API allows you to build Android applications that can communicate with Empatica E4
First of all, you need to make sure your phone runs at least Android 4.4 KitKat (API level 19). Android 6.0 or newer is recommended. This version is tested also on latest Android 9 and 10. NOTE: Android 4.3 doesn't offer a stable enough connection, while previous versions don't support Bluetooth 4.0 (BLE) at all, and, therefore, are not compatible with the Empatica API.
E4link 1.0.0 release is meant to be used with Android Studio 3.5 or later.
Once equipped with a supported phone, you need to navigate to Empatica Connect Developer Area and request to become a developer. You will find your API key and all the download links there.
Dependencies
E4link has the following dependency:
Installation instructions
Download the SDK from Empatica Connect Developer Area
Open your project in Android Studio
Open your main build.gradle (project root) and change the trailing lines to:
Copy
E4link-1.0.0.aar
in the folderlibs
in theapp
folder (or in the folder with the name of your app). If the folder doesn't exist, create it.Open your app build.gradle and, in the dependencies { ... } block, add the following line:
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.empatica.empalink:E4link:1.0.0@aar'
Make sure your
build.gradle
has aminSdkVersion 19
(or higher) line
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
Usage
First of all, you need to instantiate an EmpaDeviceManager
, passing your application context, and references to classes implementing EmpaDataDelegate
and EmpaStatusDelegate
.
Then, you must register your API Key using the Device Manager's authenticateWithAPIKey()
method.
Here's an example:
public class MainActivity extends Activity implements EmpaDataDelegate, EmpaStatusDelegate {
private EmpaDeviceManager deviceManager;
protected void onCreate(Bundle savedInstanceState) {
[...]
deviceManager = new EmpaDeviceManager(getApplicationContext(), this, this);
deviceManager.authenticateWithAPIKey("YOUR API KEY");
}
[...]
}
When the Device Manager is ready for use, your EmpaStatusDelegate
will receive the EmpaStatus.READY
value via didUpdateStatus()
.
The Device Manager is now ready to scan for Empatica Devices, using: deviceManager.startScanning()
.
If any devices are in range, you will receive them through the EmpaStatusDelegate
callback didDiscoverDevice(BluetoothDevice device, String deviceLabel, int rssi, boolean allowed)
.
If allowed
is true, you can then connect to the device as follows: deviceManager.connectDevice(device)
.
If the connection request is successful, the device will start streaming data, which will be transferred to your EmpaDataDelegate by invoking its callback methods.
Additional info
Please check the Javadoc documentation for details about all the available methods.