Unity Plugin - Android SDK
Introduction
This Unity plug-in can be applied to Android platform for connecting Lovense toys and sending control commands.
Compatibility
Unity version: >= 2019.4.0
Api Compatibility Level:
- For
.Net 4.x
, the import package name isandroidPlugin_.Net4.x.unitypackage
. - For
.Net Framework
, the import package name isandroidPlugin_.NetFramework.unitypackage
. - For
.Net Standard 2.0
, the import package name isandroidPlugin_.NetStandard2.0.unitypackage
. - For
.Net Standard 2.1
, the import package name isandroidPlugin_.NetStandard2.1.unitypackage
.
Import the plugin
Download the plugin package from here. The latest version of the current plugin is V1.4 click to view version records
Import the appropriate package based on your project's Api Compatibility Level.
Select all options and click import.
The LovenseDemo folder is an example that you can refer to. Removing it won't affect the functionality. For specific Android build configuration, you can refer to the Android SDK example code configuration: android native sdk.
Guide
1 SetDeveloperToken
First, initialize the developer information. If not set successfully, searching for toys will respond with code 99.
LovenseAndroidSDK.GetInstance().SetDeveloperToken("xxxxxxxxx");
2 Search toys/Stop Searching
Search for toys, add search event listeners, and start searching for toys. You can refer to the following steps and main code.
2.1 Subscribe to search events
LovenseAndroidSDK.GetInstance().SubscribeSearchEvent(OnSearchToysResult);
private void OnSearchToysResult(SearchToysResultType type, SearchingErrorData data)
{
// process the search result
}
For callback parameter details, please refer to SearchToysResultType and SearchingErrorData
2.2 Subscribe to new toy discovery events
LovenseAndroidSDK.GetInstance().SubscribeToysGotEvent(OnGetNewToy);
private void OnGetNewToy(LovenseAndroidToy toy)
{
// process the new toy
}
For callback parameter details, please refer to LovenseAndroidToy
2.3 Start searching
LovenseAndroidSDK.GetInstance().SearchToys();
2.4 Stop searching
LovenseAndroidSDK.GetInstance().StopSearching();
3 Connect toys
Connect toys based on the toy ID found during search. You can refer to the following steps and main code.
3.1 Subscribe to toy connection change events
LovenseAndroidSDK.GetInstance().SubscribeConnectionChangedEvent(OnConnectionChanged);
private void OnConnectionChanged(string toyId, ToyStatus status)
{
// process the connection status change
}
For callback parameter details, please refer to ToyStatus
3.2 Start connection
LovenseAndroidSDK.GetInstance().ConnectToy(strToyId);
3.3 Disconnect
LovenseAndroidSDK.GetInstance().DisConnectToy(strToyId);
4 Query toy information
After connecting to the toy, you can query more detailed information about the toy. You can refer to the following main code.
4.1 Subscribe to toy information acquisition events
LovenseAndroidSDK.GetInstance().SubscribeDeviceInfoGotEvent(OnGetTypeInfo);
private void OnGetTypeInfo(string toyId, DeviceTypeUpdateInfo data)
{
// process the device type info
}
For parameter details, please refer to SubscribeDeviceInfoGotEvent
4.2 Add device type listener for the toy
LovenseAndroidSDK.GetInstance().AddDeviceTypeListener(toyId);
4.3 Send device type query command
LovenseAndroidSDK.GetInstance().SendCommandWithoutValue(toyId, LovenseCommandType.GET_DEVICETYPE);
For parameter details, please refer to SendCommandWithoutValue
5 Monitor battery level
5.1 Subscribe to toy battery events
LovenseAndroidSDK.GetInstance().SubscribeBatteryChangedEvent(OnGetBattery);
private void OnGetBattery(string toyid, int battery)
{
// process the battery level
}
5.2 Add battery listener for the toy
LovenseAndroidSDK.GetInstance().AddBatteryListener(toyId);
5.3 Send battery query command
LovenseAndroidSDK.GetInstance().SendCommandWithoutValue(toyId, LovenseCommandType.GET_BATTERY);
6 Monitor command response results
6.1 Subscribe to command result events
LovenseAndroidSDK.GetInstance().SubscribeCommandResultEvent(OnCommandResult);
public void OnCommandResult(CommandResultType type, object obj)
For parameter details, please refer to SubscribeCommandResultEvent
6.2 Add command result listener for the toy
LovenseAndroidSDK.GetInstance().AddCommandResultListener(toyId);
7 Send single command
LovenseAndroidSDK.GetInstance().SendCommandWithoutValue(toyId, LovenseCommandType);
LovenseAndroidSDK.GetInstance().SendCommand(toyId, new LovenseCommand() {
});
Sending different command types requires different parameter types and values. For details, please refer to LovenseCommandType, or check SendCommand
8 Send Functions
LovenseAndroidSDK.GetInstance().SendFunctions(ids, commands, time, runtime, pausetime);
For parameter details, please refer to SendFunctions
9 Send Pattern
LovenseAndroidSDK.GetInstance().SendPattern(ids, typeList, valueList, time, intervalTime);
For parameter details, please refer to SendPattern
10 Send Preset
LovenseAndroidSDK.GetInstance().SendPreset(ids, typeList, valueList, time, intervalTime);
For parameter details, please refer to SendPreset
11. Send Stop
LovenseAndroidSDK.GetInstance().StopAll(ids);
For parameter details, please refer to StopAll
Interface
LovenseAndroidSDK
Method
GetInstance
Description:
Get the singleton instance of LovenseAndroidSDK
Parameters: None
Return:
LovenseAndroidSDK instance
SetDeveloperToken
Description:
Set the developer token. You can get your developer token from the developer dashboard.
Parameters:
Name Type Default Required Description token string yes Developer token Return: None
SubscribeSearchEvent
Description:
Subscribe to search result event responses
Parameters:
Name Type Default Required Description callback UnityAction<SearchToysResultType,SearchingErrorData> yes callback listener Return: None
SubscribeToysGotEvent
Description:
Subscribe to new toy discovery events
Parameters:
Name Type Default Required Description callback UnityAction<LovenseAndroidToy> yes callback listener Return: None
SearchToys
Description:
Search for toys. After calling this function, SubscribeSearchEvent and SubscribeToysGotEvent will respond with callbacks.
Parameters: None
Return: None
StopSearching
Description:
Stop searching for toys. If this function is not called, the toy search will automatically end after a certain time.
Parameters: None
Return: None
SubscribeConnectionChangedEvent
Description:
Subscribe to connection event responses
Parameters:
Name Type Default Required Description callback UnityAction<string,ToyStatus> yes toyId and connection status Return: None
ConnectToy
Description:
Connect to a toy. When the connection status changes, SubscribeConnectionChangedEvent will respond.
Parameters:
Name Type Default Required Description ids string/string[] yes ID of the toy to connect Return: None
DisConnectToy
Description:
Disconnect from a toy. When the connection status changes, SubscribeConnectionChangedEvent will respond.
Parameters:
Name Type Default Required Description ids string/string[] yes ID of the toy to disconnect Return: None
SubscribeDeviceInfoGotEvent
Description:
Subscribe to events for receiving new toy information
Parameters:
Name Type Default Required Description listener UnityAction<string,DeviceTypeUpdateInfo> yes toyId and updated toy information Return: None
AddDeviceTypeListener
Description:
Set up listeners for toys that need to monitor device type, and need to send query commands (LovenseCommandType.GET_DEVICETYPE). After successful sending, SubscribeDeviceInfoGotEvent will respond.
Parameters:
Name Type Default Required Description id string yes Toy ID Return: None
SubscribeBatteryChangedEvent
Description:
Subscribe to toy battery change events
Parameters:
Name Type Default Required Description listener UnityAction<string,int> yes toyId and battery level Return: None
AddBatteryListener
Description:
Add battery monitoring for toys that need battery level monitoring. After monitoring is added, SubscribeBatteryChangedEvent will respond.
Parameters:
Name Type Default Required Description toyId string yes Toy ID Return: None
SubscribeCommandResultEvent
Description:
Subscribe to command result event responses when sending commands to toys.
Parameters:
Name Type Default Required Description listener UnityAction<CommandResultType,object> yes Result type and result information
If the result is CommandResultType.SUCCESS, the object type is string. If the result is CommandResultType.FAILED, the object type is CommandErrorData
- Return: None
AddCommandResultListener
Description:
Add command result listener for toys.
Parameters:
Name Type Default Required Description toyId string yes toy's ID Return: None
SendCommandWithoutValue
Description:
Send commands that don't require parameters to toys.
Parameters:
Name Type Default Required Description toyId string yes toy's ID type LovenseCommandType yes Command type
Commands that don't require parameters can be found in LovenseCommandType
- Return: None
SendCommand
Description:
Send commands that require parameters to toys.
Parameters:
Name Type Default Required Description toyId string yes toy's ID command LovenseCommand yes Command object
Command types that require more than 1 parameter inherit from LovenseCommand. See LovenseCommandType for details.
- Return: None
SendFunctions
Description:
Send function commands to the toys.
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control commands List<LovenseCommand> yes See LovenseCommand timeSec float yes The total runtime in second, "0" = indefinite time length. loopRunningSec float 0
no time running for each command loop in second loopPauseSec float 0
no time gap for each command loop in second Return: None
SendPattern
Description:
Send a series of functions to the toys, they will execute all the functions in
types
according to the order of the level invalues
with the interval ofintervalsMs
.Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control types List<LovenseCommandType> yes See LovenseCommandType strengthValues List<int> yes The order of the levels timeSec float yes The total runtime in second, "0" = indefinite time length. intervalsMs int 150 no The level interval in milliseconds, should be greater than 100, default 150 Return: None
SendPreset
Description:
Send a preset command to the toys.
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control, mode int yes The preset name to send, we provide four preset patterns: 0: earthquake
,1:fireworks
,2:pulse
,3:wave
timeSec float yes The total runtime in second, "0" = indefinite time length. Return: None
StopAll
Description:
Send a stop command to the toys.
Parameters:
Name Type Description toyIds List<string>/string The toys you want to stop Return: None
GetSupportedCommands
Description:
Obtain Command types supported by toys through their types
Parameters:
Name Type Description type string the type of toy Return: List<LovenseCommandType>
LovenseAndroidToy
Description:
The information of the Lovense toy
Properties:
Name Type Description toyId string the toy's id version int the toy's version toyVersion int The version number of this type of toy, such as Lush version 1, 2, 3 type string the toy's type connected bool the toy's connection status battery int the toy's battery rssi int the toy's rssi deviceName string the toy's name uuid string the toy's uuid macAddress string the toy's macaddress
LovenseCommand
Description:
The toy control command
Properties:
Name Type Description type LovenseCommandType See below value int Function level
Function Level:
Type | Range |
---|---|
GET_DEVICETYPE | - |
GET_BATTERY | - |
GET_POSITION | - |
START_FEEDBACK | - |
STOP_FEEDBACK | - |
GET_TOUCHMODE | - |
GET_TOUCH_VALUE | - |
GET_TOUCH_LEVEL | - |
VIBRATE | 0-20 |
VIBRATE1 | 0-20 |
VIBRATE2 | 0-20 |
VIBRATE3 | 0-20 |
ROTATE | 0-20 |
PUMP | 0-3 |
THRUSTRING | 0-20 |
FINGERING | 0-20 |
SET_POSITION | 0-100 |
OSCILLATE | 0-20 |
SET_TOUCH_LEVEL | 1-3 |
SET_TOUCHMODE | the enum of TouchModeOfMission2 |
SET_TOUCH_VALUE | level:1-3,strength:0-100 |
THRUST_AND_DEPTH | depth:1-3,thrust:0-20 |
STROKE | level:0-20,strokeLow:0-20,strokeHigh:0-20 |
To determine the number of parameters required, you can also use the integer value of the enum type: 0-99 require no parameters, 100-199 require one parameter, 200-299 require two parameters, 300-399 require three parameters.
LovenseCommandType
Description:
The enum of the toy function type.
Enum:
Type Required class for sending commands GET_DEVICETYPE LovenseCommandType GET_BATTERY LovenseCommandType GET_POSITION LovenseCommandType START_FEEDBACK LovenseCommandType STOP_FEEDBACK LovenseCommandType GET_TOUCHMODE LovenseCommandType GET_TOUCH_VALUE LovenseCommandType GET_TOUCH_LEVEL LovenseCommandType VIBRATE LovenseCommand VIBRATE1 LovenseCommand VIBRATE2 LovenseCommand VIBRATE3 LovenseCommand ROTATE LovenseCommand PUMP LovenseCommand THRUSTRING LovenseCommand FINGERING LovenseCommand SET_POSITION LovenseCommand OSCILLATE LovenseCommand SET_TOUCHMODE LovenseCommand SET_TOUCH_LEVEL LovenseCommand SET_TOUCH_VALUE LovenseMission2Command THRUST_AND_DEPTH LovenseSolaceCommand STROKE LovenseSolaceProCommand
SearchToysResultType
Description:
The type of search results.
Enum:
Type Description ERROR Search error occurred FINISH Search completed
SearchingErrorData
Description:
Error information when search fails.
Properties:
Name Type Description code string See below msg string error message
Code "4"/"98": Bluetooth permission, 99: Developer token not set or developer token has issues
ToyStatus
Description:
Connection status.
Enum:
Type Description CONNECTING Connecting CONNECTED Connected CONNECTFAILED Connection failed DISCONNECT Disconnected DISCOVERED Bluetooth signal lost
DeviceTypeUpdateInfo
Description:
Updated toy information after sending commands.
Properties:
Name Type Description type string toy's type macAddress string toy's mac address version int toy's version toyVersion int toy's generation number
CommandResultType
Description:
Result after sending commands
Enum:
Type Description SUCCESS Command executed successfully ERROR Command execution failed
CommandErrorData
Description:
Information about command execution failure
Properties:
Name Type Description toyId string ID of the toy that failed code string Error code message string Error information
Version Records
[Version1.4] - 2025-07-07
- Optimized overall workflow
- Updated to SDK version 1.5.2
- Added more commands
[Version1.3] - 2023-11-21
- Add Depth command.
[Version1.2] - 2023-11-01
- Add Vibrate3 command and Multiply(The Lapics toy is the only one that is currently supported) command.
[Version1.1] - 2023-09-12
Add config file about toy support instructions. And add a function that can query toy support instructions
Change type of 'strengthValues' int[] to List<int> in pattern function
Change time type int to float.
[Version1.0] - 2023-08-20
Functions
Pattern
Preset
Connect/DisConnect
Type/Battery