Android SDK
The Lovense Android SDK is a set of application interfaces based on Android 4.3 and above. Use this SDK to develop applications for Android mobile devices. By calling the Lovense SDK interface, you can easily control Lovense toys and build applications with rich functions and strong interactivity.
Step 1: Get the developer token
Go to the developer dashboard and get your developer token.
Step 2: Download and extract the Lovense SDK
Step 3: Include SDK and Configure
Copy the following file to your
libs
directory.Add
lovense.arr
to your app build.gradle. Configurelibs
in the program build.gradle.app build.gradle:
implementation files ('libs/lovense.aar')
program build.gradle:
add other implementations to app build.gradle:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) // toy sdk need implementation all kits of below implementation 'org.greenrobot:eventbus:3.3.1' implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.tencent:mmkv:1.3.7' implementation 'androidx.room:room-runtime:2.5.0-alpha01' implementation 'net.zetetic:android-database-sqlcipher:4.5.3' implementation 'com.github.getActivity:XXPermissions:18.3' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0' implementation 'me.jessyan:retrofit-url-manager:1.4.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.20' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'androidx.core:core-ktx:1.13.1' }
Configure permissions and register service in AndroidManifest.xml
Permission list
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Step 4: Connect Lovense toys and send commands
// Pass your token into the Lovense framework
Lovense.getInstance(getApplication()).setDeveloperToken("Your token");
// Add a scan success notification
Lovense.getInstance(getApplication()).searchToys(new OnSearchToyListener() {
@Override
public void onSearchToy(LovenseToy lovenseToy) { } // Find toys
@Override
public void finishSearch() { } // Scan finish
@Override
public void onError(LovenseError msg) { } // error
});
//Add a connection success notification
Lovense.getInstance(getApplication()).connectToy(toyId, new OnConnectListener() {
@Override
public void onConnect(String toyId,String status) { // Toy connection status
switch (status) {
case LovenseToy.STATE_CONNECTING:
break;
case LovenseToy.STATE_CONNECTED:
break;
case LovenseToy.STATE_FAILED:
break;
case LovenseToy.SERVICE_DISCOVERED:
break;
}
}
@Override
public void onError(LovenseError lovenseError) {} // Connection error
});
// Add sending command notification
Lovense.getInstance(getApplication()).addListener(toyId, new OnCallBack() {});
// Search for the toys over Bluetooth
Lovense.getInstance(getApplication()).searchToys(new OnSearchToyListener());
//Stop searching for toys
Lovense.getInstance(getApplication()).stopSearching();
// Save the toys
Lovense.getInstance(getApplication()).saveToys(lovenseToys, new OnErrorListener());
// Retrieve the saved toys
Lovense.getInstance(getApplication()).listToys(new OnErrorListener());
// Connect the toy
Lovense.getInstance(getApplication()).connectToy(toyId,new OnConnectListener());
// Disconnect the toy
Lovense.getInstance(getApplication()).disconnect(toyId);
// Send a command to the toy
Lovense.getInstance(getApplication()).sendCommand(toyId,LovenseToy.COMMAND _VIBRATE,vibrateLevel);
Command list
Command | Description |
---|---|
COMMAND_VIBRATE | Vibrate the toy. The parameter must be between 0 and 20. |
COMMAND_ROTATE | Rotate the toy. The parameter must be between 0 and 20. |
COMMAND_ROTATE_CLOCKWISE | Rotate clockwise. The parameter must be between 0 and 20. |
COMMAND_ROTATE_ANTI_CLOCKWISE | Rotate anti-clockwise. The parameter must be between 0 and 20. |
COMMAND_ROTATE_CHANGE | Change the rotation direction |
COMMAND_AIR_IN | Airbag inflation for n seconds. The parameter must be between 1 and 3. |
COMMAND_AIR_OUT | Airbag deflation for n seconds. The parameter must be between 1 and 3. |
COMMAND_AIR_AUTO | Cycle airbag inflation for n seconds and air deflation for n seconds. The parameter must be between 0 and 3 (0 means stop). |
COMMAND_VIBRATE1 | Activate the first vibrator at level n. The parameter must be between 0 and 20. |
COMMAND_VIBRATE2 | Activate the second vibrator at level n. The parameter must be between 0 and 20. |
COMMAND_VIBRATE_FLASH | Vibrate the toy at level n and flash the light at the same time. |
COMMAND_FLASH | Flash the light 3 times |
COMMAND_LIGHT_OFF | Turn off the light (saved permanently). |
COMMAND_LIGHT_ON | Turn on the light (saved permanently). |
COMMAND_GET_LIGHT_STATUS | Get the light's status (1: on, 0: off) |
COMMAND_ALIGHT_OFF | Turn off Domi/Domi 2 light (saved permanently) |
COMMAND_ALIGHT_ON | Turn on the Domi/Domi 2 light (saved permanently) |
COMMAND_GET_ALIGHT_STATUS | Get the Domi/Domi 2 light status (1: on, 0: off) |
COMMAND_GET_BATTERY | Get battery status |
COMMAND_GET_DEVICE_TYPE | Get device/toy information |
COMMAND_START_MOVE | Start tracking the toy movement (0-4) |
COMMAND_STOP_MOVE | Stop tracking the toy movement |
COMMAND_PRESET | Vibrate with a preset pattern. Patterns range from 1 to 10. n=0 will stop vibrations. |
COMMAND_FLEXER_VIBRATE | Control the vibration of Flexer. The parameter must be between 0 and 20. |
COMMAND_FLEXER_FINGER | Control the fingering motion of Flexer. The parameter must be between 0 and 20. |
COMMAND_VIBRATE3 | Activate the third vibrator at level n. The parameter must be between 0 and 20. |
COMMAND_THRUST | Thrust the toy. The parameter must be between 0 and 20. |
COMMAND_MULTIPLY | Control three vibrators with different strength level for Lapis. Level range is 0 - 20, set level to -1 for remaining strength level from previous function. |
COMMAND_SOLACE | Control thrust and depth level separately for Solace. Level range is 0 - 20 for thrusting, and 1-3 for depth. Set level to 0 for thrusting will make the toy stop no matter what is the level value for depth. If the depth is not specified, the toy will act with the set thrusting level and default depth level value 1. |
COMMAND_GET_TOUCH_MODE | Get current mode from 'mission2' toy. The result will be one of [0, 1, 2, 3, 5]. |
COMMAND_SET_TOUCH_MODE | Set current mode to 'mission2' toy. The parameter must be one of [0, 1, 2, 3, 5] |
COMMAND_GET_TOUCH_VALUE | Get touch attenuation value from 'mission2' toy. That will return all level. |
COMMAND_SET_TOUCH_VALUE | Set touch attenuation value to 'mission2' toy. The parameter level must be between 1 and 3, attenuation value must be between 0 and 100. |
COMMAND_GET_TOUCH_LEVEL | Get touch attenuation level from 'mission2' toy. The result will be between 1 and 3. |
COMMAND_SET_TOUCH_LEVEL | Set touch attenuation level to 'mission2' toy. The parameter must be between 1 and 3. |
COMMAND_GET_SITE | Get current position from the 'solacePro' toy. |
COMMAND_SET_SITE | Set position to the 'solacePro' toy. The parameter must be between 0 and 100. |
COMMAND_SPEED | Thrust the 'solacePro' toy with fixed interval and a certain speed. Three parameters: speed, start and end. The parameter must be between 0 and 20. |
COMMAND_START_FEEDBACK | Start tracking the 'solacePro' toy movement. Return data : speed, direction and position. |
COMMAND_STOP_FEEDBACK | Stop tracking the 'solacePro' toy movement. |
COMMAND_GET_AUTO_SWITCH | Get auto switch status via OnCallBackGetAutoSwitchListener. Returns two Int parameters: autoStop and reconnectToLastLevel, where each value is either 1 (on) or 0 (off) |
COMMAND_SET_AUTO_SWITCH | Set auto switch status with two parameters: 1 (on) or 0 (off). The IntArray consists of two values: [autoStop, reconnectToLastLevel]. |
Callback list
Callback | Description |
---|---|
OnSearchToyListener | Found toy list |
OnConnectListener | Toy connected status |
OnSendCommandErrorListener | Send Command error, extends OnCallBack |
OnCallBackBatteryListener | Battery status, extends OnCallBack. This is deprecated. Use OnCallBackBatteryV2Listener instead. |
OnCallBackBatteryV2Listener | This callback returns the current battery level and the working status of the device (isWork). |
OnCallBackDeviceTypListener | Device information, extends OnCallBack |
OnCallBackLightStatusListener | Light indicator, extends OnCallBack |
OnCallBackAidLightStatusListener | Domi/Domi 2 light indicator, extends OnCallBack |
OnCallBackMoveListener | Toy movement updates, extends OnCallBack |
OnCommandSuccessListener | Command success, extends OnCallBack |
OnCommandErrorListener | Command Error, extends OnCallBack |
OnCallBackMission2Listener | All command callbacks from 'mission2' toy |
OnCallBackSolaceProListener | All command callbacks from 'solacePro' toy |
OnCallBackGetAutoSwitchListener | Get auto switch status, extends OnCallBack |
OnCallBackBatteryV2Listener
This callback returns the current battery level and the working status of the device (isWork).
battery: The current battery level.
isWork: Indicates whether the device is currently working (e.g., vibrating). When isWork is true, the battery level might be inaccurate due to ongoing device activity. In this case, the battery property of the Toy class will not be updated. When isWork is false, the battery level is considered accurate, and the Toy's battery property will be updated accordingly.
Sync to Lovense patterns
After completing the Native SDK integration, you can easily build features that enable users to sync Lovense toys with media by utilizing the Pattern Playback methods. Support Android 4.3 and above.
Step 1: Initialization
Initialize the pattern player. Call this method every time you start to use the pattern syncing feature or when there is a change in the toy list.
Note: This method only needs to be called once during the whole process.
Parameters | Description | Type | Required |
---|---|---|---|
toyId | The list of connected toys’ id. | List<String> | Required |
pf | Your platform’s name. Contact us if you aren’t sure about this. | String | Required |
lovense.setupPatternPlayerWithToyIds(toyIds, pf);
Step 2: Load Pattern
Load the pattern of the media to be played. Call this method every time you open a media page or switch media.
Parameters | Description | Type | Required |
---|---|---|---|
mediaID | The media’s ID from your platform. | String | Required |
lovense.prepareForPatternWithMediaID(mediaId, new OnPrepareCallback() {
@Override
public void onComplete() {
}
@Override
public void onError(String errorMsg) {
}
});
Step 3: Play Pattern
Parameters | Description | Type | Required |
---|---|---|---|
currentTime | The playing time duration so far. The default is 0. (in ms) | Long | Optional |
totalTime | The total time of media. (in ms) | Long | Required |
lovense.playPattern(currentTime, totalTime);
Step 4: Sync with Media
If the rate or progress changes while playing the media, call the following methods to re-sync the rate and time.
Parameters | Description | Type | Required |
---|---|---|---|
rate | The playback rate. The default is 1.0. | Float | Optional |
lovense.setRate(rate);
Parameters | Description | Type | Required |
---|---|---|---|
currentTime | The playing time duration so far. (in ms) | Long | Required |
lovense.syncCurrentTime(position);
Pause the pattern when the media is paused or loading, so the toy’s reaction matches the media content.
lovense.pause();
Calling this method will pause the playing and reset the time to 0.
lovense.stop();