Introduction
The App Gallery provides a mini-app platform within the App Gallery feature of the Lovense Remote App to host full Web Apps. This will allow for flexible interfaces that can seamlessly integrate with Lovense toys.
Developers can easily and efficiently utilize these APIs to accomplish relevant tasks.
Create and Release Your Apps
Preparation
Register Lovense Developer account to access the developer dashboard.
Step 1: Go to the App Gallery Console
Visit the developer dashboard and click on App Gallery solutions, then click the “Go to Console” button.
Step 2: Create a New App and fill in the Basic Information
Click the “New App” button on the Apps page to create a new App.
Click on “Basic Information” in the sidebar an complete the form.
Example of Basic Information is displayed in App Gallery.
Example of User Privacy Protection Guidelines.
Note: If you do not need to collect user information, please select the 1st option. Otherwise, select the 2nd option.
Step 3: Develop Your App
Refer to the APIs document to find out what functionality Lovense Remote app provides.
Prerequisites
Before calling the API, it's necessary to listen for the deviceready
event to ensure that appGallery
is ready. It guarantees that the API will function properly.
- Example
document.addEventListener('deviceready', onAppGalleryReady, false)
function onAppGalleryReady() {
// appGallery is now initialized
}
Step 4: Debug Your App
Configuration File
Before debugging the app, you need to create a file, called appgallery_config.json
. The appgallery_config.json
file should be placed in the root directory of the Web App, which is used for global configuration of the app.
The file content is a JSON object with the following properties:
Attribute | Type | Default | Required | Introduction |
---|---|---|---|---|
version | String | Yes | This version of the App Gallery SDK used by the mini-app, "2" will indicate that the 2.x version is being used. - This is currently version 2 and is supported by Lovense Remote App version 7.14.0 and above. - The mini-app functionality requires support from Lovense Remote App. Each new feature added to the App Gallery SDK requires a specific version of the Lovense Remote App. Some new features in a later version of the SDK may not be compatible with earlier versions of Remote app. | |
appId | String | Yes | The appId is the App ID you create on App Gallery Console. | |
appVersion | String | Yes | The appVersion is the version number you create on App Gallery Console. | |
permission | Array | No | The permissions required by the Web App. Available permissions are: - user_info: User information - toy_info: Toy information | |
allowDomains | Array | No | The allowed list of server domains is a restrictive measure implemented to ensure application security. In the case of API calls made by the web app, communication is limited to the domain names listed. For instance, only HTTP requests to the authorized domain names are allowed. |
Get the appId
and appVersion
from App Gallery Console.
Example (appgallery_config.json
):
{
"version": "2",
"appId": "is6cbb054xxxxea42xxx17f7xxx1abxxxxx",
"appVersion": "1.0",
"permission": ["user_info", "toy_info"],
"allowDomains": ["*.example.com"]
}
Generate Debug QR Code
You can deploy the web app you're developing locally or to a server. Then generate the QR code, the link should be: https://server:port/index.html
Developer Mode
There is a switch of Developer Mode
on Lovense Remote app for running web apps under development. Go to Settings page then tap “Settings” at the top three times to make the switch visible.
With Developer Mode enabled, Lovense Remote app can run the web app via scanning the QR code.
Run your App using Lovense Remote app
After scanning the QR Code, Lovense Remote app will directly open your App page.
When you want to see the logs and additional debugging information output by the console, click on the button
vConsole
.Click on the button
...
(represented by three dots) in the top-right corner.Clicking
settings
will open the settings pop-up box, displaying two options:Auto-Clear Cache
andEnable allowDomains
. By default,Auto-Clear Cache
is enabled andEnable allowDomains
is disabled.If the app needs to access other links or resources via the network, you need to format all the access link domains, and configure into the
allowDomains
properties in theappgallery_config.json
file, and enable the switch for theallowDomains
. Then selectReopen
or rescan the QR code to check.
Step 5: Package Your Code
After completing the development, it is necessary to select all the files and package your code as a zip file. Please ensure that you do not directly select the outer folder for compression. Please follow these requirements.
- All files must be placed in the root directory.
- The zip file must contain the index.html file.
- The zip file must contain the configuration file: appgallery_config.json.
- The size of the zip file should be less than 100 MB.
Step 6: Submit for Review
After debugging your program, submit the code for review in the App Gallery Console.
If the version that has been submitted for review is rejected or revoked, click the “+” icon to create a new version for submission.
Once the App is approved, your app will be displayed in App Gallery.
User Authorization
Access to user information requires user authorization. When calling userManager.getAuthCode, a pop-up window will appear to ask the user if he/she wants to accept.
Authorization Process
Get authCode
The developer can use userManager.getAuthCode to get authCode.
When calling it
- scope is a core parameter that affects accessToken's ability to access resources.
- authCode is valid for a single use and will expire after that. Repeated use of authCode triggers alerts.
- authCode will expire in 3 minutes, so please get the accessToken and userId using authCode as soon as possible.
Use appSecret to encrypt authCode into sign
How to encrypt:
- The developer uses App Secret as the key to encrypt the authCode to produce a sign. Go to App Gallery Console to get the App Secret.
- The encryption method, signType, can only use HmacSHA256 at this time.
- The encrypted string should be Base64 encoded.
Lovense Remote server will compare the decrypted sign to authCode, and access will be denied if the comparison fails.
Java Code Example
import sun.misc.BASE64Encoder;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
public String useSecretGenerateSign(String authCode, String appSecret) throws Exception {
Mac sha256HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(appSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256HMAC.init(secretKey);
byte[] bytes = sha256HMAC.doFinal(authCode.getBytes(StandardCharsets.UTF_8));
return (new BASE64Encoder()).encodeBuffer(bytes);
}
Get Access Token and User ID using authCode
The developer can use Get Access Token HTTP API and Get User Info HTTP API to get accessToken and userId.
Calling the interface with authCode to get an accessToken also returns a refreshToken, which can be used to refresh a new accessToken within the refreshToken's validity period.
The accessToken is used to access the lovense APIs, which determine the scope of the accessToken's privileges and only allow access to interfaces within that scope.
Java Code Example
URI uri = new URIBuilder().setScheme("https").setHost("appgallery.lovense.com").setPath("/remote-dev-api/oauth").build();
HttpPost post = new HttpPost(uri);
post.setHeader("Content-Type", "application/json;charset=utf8");
post.setHeader("developerToken", developerToken);
// user HttpClient
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
CloseableHttpResponse response = httpClient.execute(post);
// gets the response entity from the response model
HttpEntity responseEntity = response.getEntity();
// assemble request body
String appId = "your appId";
String appSecret = "your appSecret";
String grantType = "authorizationCode"; // or refreshToken
Param param = new Param();
param.setAppId(appId);
param.setGrantType(grantType);
if (Objects.equals("refreshToken", param.getGrantType())) {
String refreshToken = "Persist refreshToken in your server";
param.setFreshToken(refreshToken);
} else if (Objects.equals("authorizationCode", param.getGrantType())) {
String authCode = "authCode obtained from the sdk";
String sign = this.useSecretGenerateSign(param.getAuthCode(), appSecret);
param.setAuthCode(authCode);
param.setSign(sign);
param.setSignType("HmacSHA256"); // Currently, only HmacSHA256 is accepted
}
StringEntity entity = new StringEntity(JsonUtil.toJson(param), "UTF-8");
post.setEntity(entity);
// send request
String contentStr = EntityUtils.toString(responseEntity);
DataResponse content = JsonUtil.toBean(contentStr, DataResponse.class);
OAuthResponseData data = JsonUtil.toBean(JsonUtil.toJson(content.getData()), OAuthResponseData.class);
class AccessUserInfo {
private boolean result;
private int code;
private Strig message;
private Object data;
// omit getter and setter methods
}
class OAuthResponseData {
private String accessToken;
private Long expiresIn;
private String refreshToken;
private Long reExpiresIn;
private String userId;
// omit getter and setter methods
}
Get userInfo using accessToken
The developer can use this interface to get userInfo:
GetUserInfo Request
Java Code Example
// obtain user information using accessToken
URI uri = new URIBuilder().setScheme("https").setHost("appgallery.lovense.com").setPath("/remote-dev-api/user/info").build();
HttpPost post = new HttpPost(uri);
post.setHeader("Content-Type", "application/json;charset=utf8");
post.setHeader("developerToken", developerToken); // your developerToken
post.setHeader("accessToken", accessToken); // accessToken from step2
// user HttpClient
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
CloseableHttpResponse response = httpClient.execute(post);
// gets the response entity from the response model
HttpEntity responseEntity = response.getEntity();
String contentStr = EntityUtils.toString(responseEntity);
DataResponse content = JsonUtil.toBean(contentStr, DataResponse.class);
AccessUserInfo data = JsonUtil.toBean(JsonUtil.toJson(content.getData()), AccessUserInfo.class);
class AccessUserInfo {
private boolean result;
private int code;
private Strig message;
private Object data;
// omit getter and setter methods
}
class AccessUserInfo {
private String name;
// omit getter and setter methods
}
Server API
Get Access Token HTTP API
API URL: https://appgallery.lovense.com/remote-dev-api/oauth
Method: POST
Content Type: application/json
Headers:
Name | Description | Type | Required |
---|---|---|---|
developerToken | Developer token | string | yes |
Parameters:
Name | Description | Type | Note | Required |
---|---|---|---|---|
appId | Appcation ID | string | Get Appcation ID from App Gallery Console | yes |
grantType | Decide whether to get authCode or refreshToken | string | authorizationCode: used when exchanging authCode for accessToken. refreshToken: used when exchanging refreshToken for accessToken | yes |
authCode | The authCode obtained in the first step | string | Required if grantType=authorizationCode | no |
sign | Sign of authCode. It is used to verify that the authcode is legal. | string | Required if grantType=authorizationCode and use appSecret as encryption key | no |
signType | Encryption method | string | Required if grantType=authorizationCode and HmacSHA256 only for now. | no |
refreshToken | The refreshToken obtained previously | string | Required if grantType=refreshToken | no |
Response:
Name | Description | Type |
---|---|---|
result | Interface request result | boolean |
code | Interface response value | int |
message | The interface returns a message, "success" on success. | string |
accessToken | - | string |
expiresIn | The timestamp of accessToken | number |
refreshToken | - | string |
reExpiresIn | The timestamp of refreshToken | number |
userId | The user id of the account | string |
Note:
- The users can cancel the authorization, once canceled, the accessToken and refreshToken will be invalidated immediately.
- When you call the interface with refreshToken, you get a new accessToken, the accessToken expiration date is refreshed and the original accessToken expires immediately. At the same time, you will get a new refreshToken, the original refreshToken will be invalid, and the validity period of the new refreshToken will not be refreshed.
Request Example:
{
"appId": "8b037229f05d4846a780f94c01217c86",
"grantType": "authorizationCode",
"authCode": "8f8039620d97682f5dc2233c0846f4c9801cd5e98e10b495cf874b01e40dff25",
"sign": "BBEEgnnb7Ff6FXTI9nnYEFHh79dZa3WW7H61I25ZALuunPuc/VPs2usZuo1cXxZE",
"signType": "HmacSHA256",
"refreshToken": ""
}
Response Example:
{
"result": true,
"code": 0,
"message": null,
"data": {
"accessToken": "C6cB322UtP14uR6DLgPRtbyBXL+wjb6NFuM1tCXMwly+6RhaCOh27euJvteoBxltRT0RYsGlEGT5aZv/WF8ZPiaNhC+L+cSoR1cnXpxFaThqkuPIWCyAFjQDR433qaeyxISeLGGFjLTxvWlwBAhRqSxTo8ahswpfRUbOHRBVxnGtDp8Ks81bEEYc4zIa0/oFxyo6+eEDPfAU/Drm0Mw/EhFfwc8lLoptF7uo20iNEQ4P73V4INLWkXbSKKOrhTwQyabEGAoOiZ2LMXEN2JxK16zL9GcVNAkaQBwEWYpNaDvX9U/tQp+A+ct/ztpPUxKWaNck1B/+FESh4aK7Jh+RK52K4sQfJL3APiU5pYl3YI4=",
"expiresIn": 1698390847916,
"reExpiresIn": 31536000,
"refreshToken": "chBKBBkUmZ2NHIcTOVKH6AX2wbkeEwA0bbJVd0LZL8+eFmWsTt9NDt78YcOwFGvsPXNABQ/Jicu7vmh8maBsaZBSgV17PyY+JcHv7x8tPYUK2yTO3Nes/mFwvkqEQaTJQ8ofqRYlnY034UojqGW2/cwaK/X3fYtdIZE1GS/X6i7WX04JpASZgaFaS5yuyp2q8Ioze4fTSt+uvtTGKv/aKhfVwhz4cdXfKGWlOt1vTEc4+1OqHjRuTDFfzBT3aD9YIldP142OPYHnBAZzXfnMK3JFNe9vvU7g/XrJR9AqJ86XfZoDkDJCGX0Y+RkxxL7oPbirOpj6PhaeyFiZkayMXQ==",
"userId": "IfoQ0JsqJ9rUKS7YzhpsHHD33TmqcDufPV6dKTnsvx3qGZ/gYkb5ZgNCKaP5cz04"
}
}
Get User Info HTTP API
API URL: https://appgallery.lovense.com/remote-dev-api/user/info
Method: POST
Content Type: application/json
Headers:
Name | Description | Type | Required |
---|---|---|---|
developerToken | Developer token | string | yes |
accessToken | The accessToken obtained in the second step | string | yes |
Response:
Name | Description | Type |
---|---|---|
result | Interface request result | boolean |
code | Interface response value | int |
message | The interface returns a message, "success" on success. | string |
name | The username that the user agrees to authorize | string |
Request Example:
curl -X POST https://appgallery.lovense.com/remote-dev-api/user/info \
-H "Content-Type: application/json" \
-H "developerToken: xxxxxx" \
-H "accessToken: xxxxxxxxxx"
Response Example:
{
"result": true,
"code": 0,
"message": null,
"data": {
"name": "lovenseDevTest"
}
}
API
User Manager
Use appGallery.getUserManager()
to get the globally unique toy manager instance.
getAuthCode
Description
After the user logs into the host app (Lovense Remote App), call this interface to obtain user information authorization and obtain an authorization code (authCode).
Parameters
Attribute Type Default Required Introduction scope String Yes Authentication Type,
authBase
: Silent authorization, no authorization pop-up will appear;
authUser
: User authorization, an authorization pop-up will appearsuccess function No Callback function for successful API call fail function No Callback function for failed API call Success callback function will receive an object with the following attributes:
Attribute Type Introduction authCode string Authorization code Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
// Get user manager instance const userManager = appGallery.getUserManager() // User authorization userManager.getAuthCode({ scope: "authUser", // Authorization type success(res) { console.log(res.authCode) // Print the obtained authorization code }, fail(err) { console.error(err.code) // Print error code console.error(err.msg) // Print error message }, })
authorize
Description
Initiate authorization requests to users in advance. Immediately after the call, a pop-up asks if the user agrees to authorize the mini-app to use a function or get some data from the user, but does not actually call the corresponding interface. If the user has previously agreed to the authorization, there will be no pop-up window, directly return success.
Parameters
Attribute Type Default Required Introduction scope String Yes Need to get permission scope: scope.writePhotosAlbum
: save the image to system albumsuccess function No Callback function for successful API call fail function No Callback function for failed API call Success callback function will receive an object with the following attributes:
Attribute Type Introduction code string Success code Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
// Get user manager instance const userManager = appGallery.getUserManager() userManager.authorize({ scope: 'scope.writePhotosAlbum', success(res) { console.log(res.code) }, fail(err) { console.error(err.code) console.error(err.msg) } })
getAuthSetting
Description
User's current authorize settings results.
Parameters
Attribute Type Default Required Introduction success function No Callback function for successful API call fail function No Callback function for failed API call Success callback function will receive an object with the following attributes:
Attribute Type Introduction authSetting AuthSetting User's Current Authorize Settings Results Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
// Get user manager instance const userManager = appGallery.getUserManager() userManager.getAuthSetting({ success(res) { console.log(res.authSetting) // res.authSetting = { // "scope.writePhotosAlbum": true // } }, fail(err) { console.error(err.code) console.error(err.msg) }, })
AuthSetting
When using getAuthSetting
to get user's current authorize settings results, will get authSetting data.
For each item in a authSetting are as follows:
Attribute | Type | Introduction |
---|---|---|
scope.writePhotosAlbum | boolean | Authorize Save to Album |
Toy
Toy Manager
Use appGallery.getToyManager()
to get the globally unique toy manager instance.
getMyToysInfo
Description
Get the information of toy list.
Parameters
Attribute Type Default Required Introduction success function No Callback function for successful API call fail function No Callback function for failed API call Success callback function will receive an object with the following attributes:
Attribute Type Introduction toyList Array Toy List Success callback function received parameters data example:
{ "toyList": [{ "showName": "Lapis", "alias": "001", "firmwareVersion": "", "type": "z10", "toyId": "6c5cb14619b1", "battery": "98", "status": "0", "isSupportFeedbackMode": true }, { "showName": "Ridge", "alias": "", "firmwareVersion": "", "type": "ridge", "toyId": "e0798d436ab4", "battery": "98", "status": "1", "isSupportFeedbackMode": true }] }
Fail callback function will receive an object with the following attributes:
Attribute | Type | Introduction |
---|---|---|
code | string | Error code |
msg | string | Error message |
Example
const toyManager = appGallery.getToyManager() // Get the toy information toyManager.getMyToysInfo({ success(res) { console.log(res.toyList) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
onMyToysChange
- Description
Set up a listener to receive updates on the connection status or quantity of toys. This will allow you to retrieve the latest information about your toys.
Parameters
Attribute Type Default Required Introduction callback function Yes Listener function for toy connection status or quantity changes. The callback function will receive an object with the following attributes:
Attribute Type Introduction toyList Array Toy List Example
const toyManager = appGallery.getToyManager() // Listen to changes in my toys toyManager.onMyToysChange(function (res) { console.log(res.toyList) })
openMyToysDialog
Description
Open the pop-up window of my toy page.
Example
const toyManager = appGallery.getToyManager() // Open My Toy Page toyManager.openMyToysDialog()
sendCommand
Description
Send toy command.
Parameters
Attribute Type Default Required Introduction command object Yes Toy command, for the reference about the toy command API, please check: Standard API success function No Callback function for successful API call fail function No Callback function for failed API call Success callback function will receive an object with the following attributes:
Attribute Type Introduction code string Success code Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
const toyManager = appGallery.getToyManager() // Send toy command toyManager.sendCommand({ command: { command: "Function", action: "Vibrate:16", timeSec: 20.28, loopRunningSec: 9.2, loopPauseSec: 4.3, stopPrevious: 1, toy: "", apiVer: 1, }, success(res) { console.log(res.code) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
startFeedbackMode
Description
Start toy feedback mode. About the toy feedback mode, please check: Toy Events API
Parameters
Attribute Type Default Required Introduction toyIdList Array No Array of toy MAC addresses. If not provided, it will start feedback mode for all connected supported toys success function No Callback function triggered when the feedback mode is successfully started fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction type string Event type toyId string Toy MAC address data object Event data Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
const toyManager = appGallery.getToyManager() // Start feedback mode toyManager.startFeedbackMode({ toyIdList: ["d802de4cd35b"], success(res) { console.log(res.type) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
stopFeedbackMode
Description
Stop toy feedback mode.
Parameters
Attribute Type Default Required Introduction toyIdList Array No Array of toy MAC addresses. If not provided, it will stop feedback mode for all connected supported toys. success function No Callback function triggered when the feedback mode is successfully stopped fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction type string Event type toyId string Toy MAC address data object Event data Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
const toyManager = appGallery.getToyManager() // Stop feedback mode toyManager.stopFeedbackMode({ toyIdList: ["d802de4cd35b"], })
Toy List
When use getMyToysInfo
to get toy list or use onMyToysChange
to listen toy list change, will get toy list data.
For each item in a toy list are as follows:
Attribute | Type | Introduction |
---|---|---|
showName | string | Toy Name |
alias | string | Toy Alias, empty string if not available |
firmwareVersion | string | Toy Firmware Version |
type | string | Toy Type, lowercase letters |
toyId | string | Toy MAC Address, lowercase letters, e.g. 6c5cb14619b1 |
battery | string | Toy Battery Level, percentage value without the percentage sign |
status | string | Toy Connection Status ("-1": Disconnected, "0": Connecting, "1": Connected) |
isSupportFeedbackMode | boolean | Toy Feedback Mode Support (true/false) |
Device
Device Manager
Use appGallery.getDeviceManager()
to get the globally unique device manager instance.
setScreenOrientation
Description
Set screen orientation.
Parameters
Attribute Type Default Required Introduction orientation string Yes Screen orientation, portrait: "portrait", landscape: "landscape" success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction code string Success code Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
const deviceManager = appGallery.getDeviceManager() // Set screen orientation deviceManager.setScreenOrientation({ orientation: "landscape", success(res) { console.log(res.code) }, fail(err) { console.error(res.code) console.error(res.msg) }, })
vibrateShort
Description
Trigger a short vibration on the phone (around 15ms)
Parameters
Attribute Type Default Required Introduction type string Yes Vibration intensity type, valid values are: heavy, medium, light success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction code string Success code Example
const deviceManager = appGallery.getDeviceManager() // Short vibration deviceManager.vibrateShort({ type: "heavy", success(res) { console.log(res.code) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
vibrateLong
Trigger a long vibration on the phone (400ms)
Parameters
Attribute Type Default Required Introduction success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Example
const deviceManager = appGallery.getDeviceManager() // Long vibration deviceManager.vibrateLong({ success(res) { console.log(res.code) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
getCurrentAccelerometer
Description
Get the current accelerometer data.
Parameters
Attribute Type Default Required Introduction success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction x string x-axis acceleration y string y-axis acceleration z string z-axis acceleration timestamp string Timestamp when the data was obtained Example
const deviceManager = appGallery.getDeviceManager() // Get the current accelerometer data deviceManager.getCurrentAccelerometer({ success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
startAccelerometerListener
Description
Start accelerometer listener.
Parameters
Attribute Type Default Required Introduction interval string normal No Listen the execution frequency of the accelerometer data callback function. Valid values are: game, ui, normal. When an invalid value is passed, normal is used success function No Callback function triggered when the accelerometer listener is successfully enabled fail function No Callback function triggered when the API call fails The interval types are as follows:
Valid Value Introduction game Applicable for updating game callback frequency, around 20ms per update ui Applicable for updating UI callback frequency, around 60ms per update normal Normal callback frequency, around 200ms per update Success callback function will receive an object with the following attributes:
Attribute Type Introduction x string x-axis acceleration y string y-axis acceleration z string z-axis acceleration timestamp string Timestamp when the data was obtained Return
Accelerometer listener ID
Example
const deviceManager = appGallery.getDeviceManager() // Start accelerometer listener const listenerId = deviceManager.startAccelerometerListener({ interval: "ui", success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
stopAccelerometerListener
Description
Stop specified or all accelerometer listeners.
Parameters
Attribute Type Default Required Introduction listenerId string No Accelerometer listener ID. If listenerId or object parameter is not passed, all accelerometer listeners will be stopped Example
const deviceManager = appGallery.getDeviceManager() // Method 1 : // Start accelerometer listener and record the corresponding listenerId const listenerId = deviceManager.startAccelerometerListener({ interval: "game", success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, }) // Stop the accelerometer listener with the corresponding listenerId deviceManager.stopAccelerometerListener({ listenerId: listenerId, }) // Method 2 : // Start accelerometer listener, default as normal deviceManager.startAccelerometerListener({ success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, }) // Stop all accelerometer listeners deviceManager.stopAccelerometerListener()
startShakeListener
Description
Start the shake listener.
Parameters
Attribute Type Default Required Introduction success function No Callback function triggered when the shake listener is successfully started fail function No Callback function triggered when the API call fails Example
const deviceManager = appGallery.getDeviceManager() // Start Shake Listener deviceManager.startShakeListener({ success() { console.log("shake") }, fail(err) { console.error(err.code) console.error(err.msg) }, })
stopShakeListener
Description
Stop the shake listener.
Example
const deviceManager = appGallery.getDeviceManager() // Stop shake listener deviceManager.stopShakeListener()
App Info
App Info Manager
Use appGallery.getAppInfoManager()
to get the global unique app info manager instance.
getAppBaseInfo
Description
Get Lovense Remote app base infomation.
Parameters
Attribute Type Default Required Introduction success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction SDKVersion string The version of App Gallery SDK language string Lovense Remote app language accountDidUpdate boolean The Lovense Remote account has been updated to another one userInfoDidUpdate boolean The user information (username or portrait) has been updated Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
const appInfoManager = appGallery.getAppInfoManager() // Get Lovense Remote app information appInfoManager.getAppBaseInfo({ success(res) { console.log(res.code) }, fail(err) { console.error(res.code) console.error(res.msg) }, })
File System
File System Manager
Use appGallery.getFileSystemManager()
to get the global unique file system manager instance.
getAppBaseInfo
Description
Save an image to the system album.
Parameters
Attribute Type Default Required Introduction fileData string Yes Cover the image to base64 string success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction code string Success code Fail callback function will receive an object with the following attributes:
Attribute Type Introduction code string Error code msg string Error message Example
// Define a saveImageToPhotosAlbum function function saveImageToPhotosAlbum() { // Get file system manager instance const fileSystemManager = appGallery.getFileSystemManager() // Save image file to photo album fileSystemManager.saveImageToPhotosAlbum({ fileData: 'PiIwoN+asbHF55KjSYdIxgKp/gdn19c6teQR2EmVmQJQFQp9FVKnGv6rwU70dzOQSRHh9Q4dNq9eX+DlKkx4JRLH6hhMsRNkn+KIUxuNDR6R+f7//+6dP3pzV+DMnP', success(res) { console.log(res.code) }, fail(err) { console.error(res.code) console.error(res.msg) }, }) }
// Get user manager instance const userManager = appGallery.getUserManager() // Can be passed userManager.getAuthSetting Check to see if the user is authorized "scope.writePhotosAlbum" this scope userManager.getAuthSetting({ success(res) { if (!res.authSetting['scope.writePhotosAlbum']) { userManager.authorize({ scope: 'scope.writePhotosAlbum', success(res) { // The user has agreed that the mini-app will use the save image to photo album function, and then calls saveImageToPhotosAlbum Interface does not pop up to ask saveImageToPhotosAlbum() }, fail(err) { console.error(err) } }) } else { saveImageToPhotosAlbum() } }, fail(err) { console.error(err) } })
Error Code
When the API call in the mini app fails, it will return the corresponding error code. You can refer to the following error code information to find a solution.
Common Error Code
Error Code | Return | Platform |
---|---|---|
10000 | Unknown error | iOS, Android |
10001 | Invalid parameter | iOS, Android |
10002 | Request failed | iOS, Android |
Function Error Code
The 2&3-digit code represents the functionality. For example, 01 represents toy commands, 02 represents audio, 11 represents accelerometer, and 12 represents user information.
Error Code | Return | Platform |
---|---|---|
20100 | Failed to parse data | iOS, Android |
20101 | Command handling error | iOS |
20200 | Audio session setup error | iOS |
20201 | Audio recording permission not granted | iOS, Android |
20202 | Audio recorder holder does not exist | iOS |
20203 | Audio recorder setup error | iOS, Android |
21100 | Device motion not available | iOS |
21101 | Device motion error | iOS |
21102 | Device motion does not exist | iOS |
21103 | Device motion holder does not exist | iOS |
21104 | Device does not support haptics | iOS |
21105 | Failed to initialize haptic device | iOS |
21106 | Device sensor error | Android |
21107 | Accelerometer sensor error | Android |
21200 | User login authorization cancelled | iOS, Android |
21201 | User not logged into Remote | iOS, Android |
21202 | Failed to retrieve user info | iOS, Android |
21203 | User account list empty | iOS, Android |
21204 | Failed to retrieve user auth code | iOS, Android |
21205 | Privacy policy not provided. Request not allowed | iOS, Android |
21206 | User denied the privacy policy. Request not allowed | iOS, Android |
21207 | Lovense Remote does not have permission to save images to the user's album | iOS, Android |
21208 | The user denied your app permission to save images to their album | iOS, Android |
21209 | The app has not yet requested permission to save images to the user's album | iOS, Android |
They represent Standard API functionality.
Error Code | Return | Platform |
---|---|---|
30000 | Invalid command | iOS, Android |
30001 | Toy not found | Android |
30002 | Toy not connected | iOS, Android |
30003 | Toy does not support this command | Android |
30004 | HTTP server not started or disabled | iOS, Android |
30005 | No connected toy supports feedback mode | iOS, Android |