DeveloperDeveloper
  • Standard Solutions
  • Cam Solutions
  • Native SDKs
  • App Gallery
  • Game Engine Plugins
  • AI
Forum
Projects Library
Dev Discord
  • Standard Solutions
  • Cam Solutions
  • Native SDKs
  • App Gallery
  • Game Engine Plugins
  • AI
Forum
Projects Library
Dev Discord
  • Game Engine Plugin
  • Unity Universal Plugin For Remote
  • Unity Plugin - Android SDK
  • Unity Plugin - iOS SDK
  • Unity Plugin - Windows
  • Unity Plugin - Dongle
  • Unity Plugin - Mac
  • Unreal Plugin For Remote
  • Windows BLE DLL (C/C++/C#)
  • Ren'Py Plugin For Remote
Got Stuck?
Forum for Lovense Developers
Support
Document Feedback

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 is androidPlugin_.Net4.x.unitypackage.
  • For .Net Framework, the import package name is androidPlugin_.NetFramework.unitypackage.
  • For .Net Standard 2.0, the import package name isandroidPlugin_.NetStandard2.0.unitypackage.
  • For .Net Standard 2.1, the import package name is androidPlugin_.NetStandard2.1.unitypackage.

Import the plugin

  1. Download the plugin package from here. The latest version of the current plugin is V1.4 click to view version records

    • androidPlugin_.Net4.x.unitypackage
    • androidPlugin_.NetFramework.unitypackage
    • androidPlugin_.NetStandard2.0.unitypackage
    • androidPlugin_.NetStandard2.1.unitypackage
  2. Import the appropriate package based on your project's Api Compatibility Level.

    image

  3. Select all options and click import.

    image

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:

    NameTypeDefaultRequiredDescription
    tokenstringyesDeveloper token
  • Return: None

SubscribeSearchEvent
  • Description:

    Subscribe to search result event responses

  • Parameters:

    NameTypeDefaultRequiredDescription
    callbackUnityAction<SearchToysResultType,SearchingErrorData>yescallback listener
  • Return: None

SubscribeToysGotEvent
  • Description:

    Subscribe to new toy discovery events

  • Parameters:

    NameTypeDefaultRequiredDescription
    callbackUnityAction<LovenseAndroidToy>yescallback 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:

    NameTypeDefaultRequiredDescription
    callbackUnityAction<string,ToyStatus>yestoyId and connection status
  • Return: None

ConnectToy
  • Description:

    Connect to a toy. When the connection status changes, SubscribeConnectionChangedEvent will respond.

  • Parameters:

    NameTypeDefaultRequiredDescription
    idsstring/string[]yesID of the toy to connect
  • Return: None

DisConnectToy
  • Description:

    Disconnect from a toy. When the connection status changes, SubscribeConnectionChangedEvent will respond.

  • Parameters:

    NameTypeDefaultRequiredDescription
    idsstring/string[]yesID of the toy to disconnect
  • Return: None

SubscribeDeviceInfoGotEvent
  • Description:

    Subscribe to events for receiving new toy information

  • Parameters:

    NameTypeDefaultRequiredDescription
    listenerUnityAction<string,DeviceTypeUpdateInfo>yestoyId 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:

    NameTypeDefaultRequiredDescription
    idstringyesToy ID
  • Return: None

SubscribeBatteryChangedEvent
  • Description:

    Subscribe to toy battery change events

  • Parameters:

    NameTypeDefaultRequiredDescription
    listenerUnityAction<string,int>yestoyId 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:

    NameTypeDefaultRequiredDescription
    toyIdstringyesToy ID
  • Return: None

SubscribeCommandResultEvent
  • Description:

    Subscribe to command result event responses when sending commands to toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    listenerUnityAction<CommandResultType,object>yesResult 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:

    NameTypeDefaultRequiredDescription
    toyIdstringyestoy's ID
  • Return: None

SendCommandWithoutValue
  • Description:

    Send commands that don't require parameters to toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdstringyestoy's ID
    typeLovenseCommandTypeyesCommand type

Commands that don't require parameters can be found in LovenseCommandType

  • Return: None
SendCommand
  • Description:

    Send commands that require parameters to toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdstringyestoy's ID
    commandLovenseCommandyesCommand 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:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control
    commandsList<LovenseCommand>yesSee LovenseCommand
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length.
    loopRunningSecfloat0notime running for each command loop in second
    loopPauseSecfloat0notime 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 in values with the interval of intervalsMs.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control
    typesList<LovenseCommandType>yesSee LovenseCommandType
    strengthValuesList<int>yesThe order of the levels
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length.
    intervalsMsint150noThe level interval in milliseconds, should be greater than 100, default 150
  • Return: None

SendPreset
  • Description:

    Send a preset command to the toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control,
    modeintyesThe preset name to send, we provide four preset patterns: 0:earthquake,1:fireworks,2:pulse,3:wave
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length.
  • Return: None

StopAll
  • Description:

    Send a stop command to the toys.

  • Parameters:

    NameTypeDescription
    toyIdsList<string>/stringThe toys you want to stop
  • Return: None

GetSupportedCommands
  • Description:

    Obtain Command types supported by toys through their types

  • Parameters:

    NameTypeDescription
    typestringthe type of toy
  • Return: List<LovenseCommandType>

LovenseAndroidToy

  • Description:

    The information of the Lovense toy

  • Properties:

    NameTypeDescription
    toyIdstringthe toy's id
    versionintthe toy's version
    toyVersionintThe version number of this type of toy, such as Lush version 1, 2, 3
    typestringthe toy's type
    connectedboolthe toy's connection status
    batteryintthe toy's battery
    rssiintthe toy's rssi
    deviceNamestringthe toy's name
    uuidstringthe toy's uuid
    macAddressstringthe toy's macaddress

LovenseCommand

  • Description:

    The toy control command

  • Properties:

    NameTypeDescription
    typeLovenseCommandTypeSee below
    valueintFunction level

Function Level:

TypeRange
GET_DEVICETYPE-
GET_BATTERY-
GET_POSITION-
START_FEEDBACK-
STOP_FEEDBACK-
GET_TOUCHMODE-
GET_TOUCH_VALUE-
GET_TOUCH_LEVEL-
VIBRATE0-20
VIBRATE10-20
VIBRATE20-20
VIBRATE30-20
ROTATE0-20
PUMP0-3
THRUSTRING0-20
FINGERING0-20
SET_POSITION0-100
OSCILLATE0-20
SET_TOUCH_LEVEL1-3
SET_TOUCHMODEthe enum of TouchModeOfMission2
SET_TOUCH_VALUElevel:1-3,strength:0-100
THRUST_AND_DEPTHdepth:1-3,thrust:0-20
STROKElevel: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:

    TypeRequired class for sending commands
    GET_DEVICETYPELovenseCommandType
    GET_BATTERYLovenseCommandType
    GET_POSITIONLovenseCommandType
    START_FEEDBACKLovenseCommandType
    STOP_FEEDBACKLovenseCommandType
    GET_TOUCHMODELovenseCommandType
    GET_TOUCH_VALUELovenseCommandType
    GET_TOUCH_LEVELLovenseCommandType
    VIBRATELovenseCommand
    VIBRATE1LovenseCommand
    VIBRATE2LovenseCommand
    VIBRATE3LovenseCommand
    ROTATELovenseCommand
    PUMPLovenseCommand
    THRUSTRINGLovenseCommand
    FINGERINGLovenseCommand
    SET_POSITIONLovenseCommand
    OSCILLATELovenseCommand
    SET_TOUCHMODELovenseCommand
    SET_TOUCH_LEVELLovenseCommand
    SET_TOUCH_VALUELovenseMission2Command
    THRUST_AND_DEPTHLovenseSolaceCommand
    STROKELovenseSolaceProCommand

SearchToysResultType

  • Description:

    The type of search results.

  • Enum:

    TypeDescription
    ERRORSearch error occurred
    FINISHSearch completed

SearchingErrorData

  • Description:

    Error information when search fails.

  • Properties:

    NameTypeDescription
    codestringSee below
    msgstringerror message

Code "4"/"98": Bluetooth permission, 99: Developer token not set or developer token has issues

ToyStatus

  • Description:

    Connection status.

  • Enum:

    TypeDescription
    CONNECTINGConnecting
    CONNECTEDConnected
    CONNECTFAILEDConnection failed
    DISCONNECTDisconnected
    DISCOVEREDBluetooth signal lost

DeviceTypeUpdateInfo

  • Description:

    Updated toy information after sending commands.

  • Properties:

    NameTypeDescription
    typestringtoy's type
    macAddressstringtoy's mac address
    versioninttoy's version
    toyVersioninttoy's generation number

CommandResultType

  • Description:

    Result after sending commands

  • Enum:

    TypeDescription
    SUCCESSCommand executed successfully
    ERRORCommand execution failed

CommandErrorData

  • Description:

    Information about command execution failure

  • Properties:

    NameTypeDescription
    toyIdstringID of the toy that failed
    codestringError code
    messagestringError information

Version Records

[Version1.4] - 2025-07-07

  1. Optimized overall workflow
  2. Updated to SDK version 1.5.2
  3. Added more commands

[Version1.3] - 2023-11-21

  1. Add Depth command.

[Version1.2] - 2023-11-01

  1. Add Vibrate3 command and Multiply(The Lapics toy is the only one that is currently supported) command.

[Version1.1] - 2023-09-12

  1. Add config file about toy support instructions. And add a function that can query toy support instructions

  2. Change type of 'strengthValues' int[] to List<int> in pattern function

  3. Change time type int to float.

[Version1.0] - 2023-08-20

  1. Functions

  2. Pattern

  3. Preset

  4. Connect/DisConnect

  5. Type/Battery

Last Updated:
Explore our Forum or Support to get more inspiration or solve your problems.
Discord Channel
It is an online real-time channel where you can communicate directly with our official administrators or many excellent developers.
Forum
It is a place for Lovense developers to communicate, where you can find solutions to problems or get inspired for your projects.
Support
Find documents and tutorials that may be helpful to you.