# Unity Android SDK Plugin

**URL:** <https://forum.developer.lovense.com/t/unity-android-sdk-plugin/72>\
**Category:** Unity\
**Created:** [July 20, 2023, 3:34am UTC](https://forum.developer.lovense.com/t/unity-android-sdk-plugin/72 "2023-07-20T03:34:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trebor](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Trebor](https://forum.developer.lovense.com/u/Trebor)\
**Post date:** [July 20, 2023, 3:34am UTC](https://forum.developer.lovense.com/t/unity-android-sdk-plugin/72/1 "2023-07-20T03:34:44Z")

</div>

**Description:**

This Unity plug-in can be applied to the Android platform to realize the function of connecting Lovense toys and sending control commands.

**Compatibility:**

Unity version \>= 2018.4.0

Scripting Backend: Mono

Api Compatibility Level: \*For .Net 4.x the import name is “\*\_Net4.x\*.unitypackage”.

Api Compatibility Level: \*For .NetFramework the imported package name is “\*.NetFramework\*.unitypackage”.

Api Compatibility Level: \*For .NetStandard2.1 the imported package name is “\*.NetStandard2.1\*.unitypackage”

Api Compatibility Level: \*For .NetStandard2.0 the imported package name is “\*.NetStandard2.0\*.unitypackage”

**Steps to integrate the plugin:**

1. Import the appropriate package based on your project’s Api Compatibility Level\*.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/lovense2/original/1X/9967af71e23acc0a669e024630c034e279ceae60.jpeg)  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/lovense2/original/1X/bb0e40f1d3b4f1c8a2a63a66bcfbd2cac4cec088.jpeg)

1. After successfully importing the plugin, a new Tools-\>LovenseAndroidDeveloper menu item will be added to the Unity menu bar. Click to enter and set the developer token, then click Save to save the token. Clicking the “Copy and modify AndroidManifest.xml and gradle file” button will generate the packaged configuration.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/lovense2/original/1X/c79de2855fc400de80c7ce98abc019dd2f0368b7.png)

**At this point, you can quickly start developing using the Android SDK. The LovenseDemo folder is an example, and deleting it does not affect your project.** **(Because the target API of the Android sdk is 28, be sure to set the Target API Level to 28)**

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/lovense2/original/1X/a72269a5373423fd3e381edd75c8249068a9bb5b.jpeg)

**Guide:**

**1.**  **Search toys**

> onSearchToyListener = new OnSearchToyListener();

> onSearchToyListener.initCallback(onSearchErrorFunc, onSearchToysFunc, onFinishFunc); //Initialize scan callback interface

> LovenseAndroidSDK.GetInstance().SearchToys(onSearchToyListener);

**2. Stop searching**

> LovenseAndroidSDK.GetInstance().stopSearching();

**3. Connect Toys**

> OnConnectListener onConnectListener = new OnConnectListener();

> onConnectListener.initCallBack(onConnectFunc, onConnectErrorFunc); //Initialize connection callback interface

> LovenseAndroidSDK.GetInstance().connectToy(toyId, onConnectListener);

**4. Battery monitoring**

> onCallBackBatteryListener = new OnCallBackBatteryListener();

> onCallBackBatteryListener.initCallBack(onCallBackBatteryListenerFunc); //Initialize the callback function

> LovenseAndroidSDK.GetInstance().addListener(toyId, onCallBackBatteryListener);

Send query:

> LovenseAndroidSDK.GetInstance().SendFunctionWithoutValue(toyId, LovenseCommandType.GET\_BATTERY);

**5. Get type**

> onCallBackDeviceType = new OnCallBackDeviceTypListener();

> onCallBackDeviceType.initCallBack(onCallBackDeviceTypeListenerFunc); //initialize the callback function

> LovenseAndroidSDK.GetInstance().addListener(toyId, onCallBackDeviceType);

Send query:

> LovenseAndroidSDK.GetInstance().SendFunctionWithoutValue(toyId, LovenseCommandType.GET\_BATTERY);

**6. Send Function**

> Single Function: LovenseAndroidSDK.GetInstance().SendFunction(toyId, command, timeSec, loopRunning, loopPause);

> Multiple Functions: LovenseAndroidSDK.GetInstance().SendFunction(toyId, commands, timeSec, loopRunning, loopPause);

> command: the type is LovenseAndroidCommand  
> commands: the type is List  
> timeSec: total running time  
> loopRunning: Running time. Use in conjunction with loopPause to control and stop the device.  
> loopPause: Suspend time. Use in conjunction with the above loopRunning to control and stop the device.

**7. Send Pattern**

> LovenseAndroidSDK.GetInstance().SendPattern(string toyId, List typeList, List valueList, int timeMs, int timeSec);

> typeList: the type of command, the type is List  
> valueList: a list of intensity changes, the type is List  
> timeMs: how often to change the intensity, time unit: milliseconds  
> timeSec: total running time, time unit: seconds

**8. Send Preset**

> LovenseAndroidSDK.GetInstance().SendPreset(string toyId, int mode, int timeSec);

There are currently four presets:

> mode=0 earthquake mode
> 
> mode=1 fireworks mode
> 
> mode=2 pulse mode
> 
> mode=3 wave mode

> timeSec: total running time, time unit: seconds

**9. Stop Toys**

> LovenseAndroidSDK.GetInstance().StopAll(string toyId);

---

<div class="post-metadata">

**Author:** ![Trebor](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Trebor](https://forum.developer.lovense.com/u/Trebor)\
**Post date:** [July 20, 2023, 3:44am UTC](https://forum.developer.lovense.com/t/unity-android-sdk-plugin/72/2 "2023-07-20T03:44:13Z")

</div>

# **Download the plugin here:**
 [https://p.lovense.com/Lovense-Unity-Plugin](https://p.lovense.com/Lovense-Unity-Plugin)
