# 戒指使用

{% hint style="info" %}
戒指只支持X2 眼镜
{% endhint %}

## 戒指信息

**该功能仅限X2+指定戒指可用**

### 注册戒指信息

<pre class="language-java"><code class="lang-java"><strong>RingIPCHelper.registerRingInfo(this);//注册戒指信息，戒指连接、imu状态、四元数数据相关信息会返回
</strong></code></pre>

### 取消注册戒指信息

<pre class="language-java"><code class="lang-java"><strong>RingIPCHelper.unRegisterRingInfo(this);//取消注册戒指相关信息
</strong></code></pre>

### 开启/关闭戒指IMU数据

<pre class="language-java"><code class="lang-java"><strong>RingIPCHelper.setRingIMU(MainActivity.this, true);//开启IMU数据
</strong><strong>RingIPCHelper.setRingIMU(MainActivity.this, false);//关闭IMU数据
</strong><strong>
</strong></code></pre>

### 戒指信息返回

<pre class="language-java"><code class="lang-java"><strong>private Launcher.OnResponseListener response = new Launcher.OnResponseListener() {
</strong>    @Override
<strong>    public void onResponse(Response response) {
</strong><strong>        if (response == null || response.getData() == null)
</strong><strong>            return;
</strong><strong>        try {
</strong><strong>            JSONObject jo = new JSONObject(response.getData());
</strong><strong>            if (jo.has("datatype") &#x26;&#x26; jo.getString("datatype").equals("ring_info")) {
</strong><strong>                boolean isRingConnected = jo.getBoolean("ring_connected");
</strong><strong>                int imuStatus = jo.getInt("ring_imu_status"); //-1：戒指未连接，0：戒指未开启IMU 1：戒指开启IMU
</strong><strong>                if (isRingConnected) { //戒指连接
</strong><strong>                    if (imuStatus != 1) {//IMU未开启
</strong><strong>                        RingIPCHelper.setRingIMU(MainActivity.this, true);//开启IMU
</strong>                    }
<strong>                } else {
</strong><strong>                    Log.i(TAG, "戒指未连接 ");
</strong>                }
<strong>            } else if (jo.has("datatype") &#x26;&#x26; jo.getString("datatype").equals("ring_quaternion")) {
</strong>                //获取四元数
<strong>                double w = jo.getDouble("w");
</strong><strong>                double x = jo.getDouble("x");
</strong><strong>                double y = jo.getDouble("y");
</strong><strong>                double z = jo.getDouble("z");
</strong>            }
<strong>        } catch (JSONException e) {
</strong>            e.printStackTrace();
        }
    }
};
</code></pre>

**JSON 数据解释**

**戒指信息 (datatype: "ring\_info")**

| 参数名称              | 类型      | 描述                                   | 示例值  |
| ----------------- | ------- | ------------------------------------ | ---- |
| ring\_connected   | Boolean | 戒指是否连接,true：连接 false:未连接             | TRUE |
| ring\_imu\_status | Integer | IMU 状态： -1 戒指未连接， 0 IMU未开启， 1 IMU已开启 | 0    |

**四元数信息 (datatype: "ring\_quaternion")**

| 参数名称 | 类型     | 描述       | 示例值          |
| ---- | ------ | -------- | ------------ |
| w    | Double | 四元数的 w 值 | 0.7379355    |
| x    | Double | 四元数的 x 值 | -0.006100293 |
| y    | Double | 四元数的 y 值 | 0.003900187  |
| z    | Double | 四元数的 z 值 | 0.6748324    |

## 戒指长按功能屏蔽及恢复

戒指默认长按会唤起眼镜Launcher，三方开发者可以通过以下接口对戒指原有的长按功能进行屏蔽以及后续恢复

<pre class="language-java"><code class="lang-java"><strong>RingIPCHelper.setRingLongClick(this, false);//屏蔽戒指在当前应用显示时长按唤起Dock
</strong><strong>RingIPCHelper.setRingLongClick(this, true);//恢复戒指在当前应用显示时长按唤起Dock
</strong></code></pre>

## 戒指触控板分离

戒指默认将其TouchPad以及其下按钮当作一体，均以MotionEvent形式发送事件给用户处理。部分开发者如果需要定义更多手势类别，将TouchPad及其下按钮事件分离，可以调用以下api，分离后，TouchPad部分触控事件以MotionEvent形式发送，其下按钮以KeyEvent事件发送（keycode为336）

<pre class="language-java"><code class="lang-java"><strong>RingIPCHelper.setRingSeparateButton(this, true);//button touchpad分离
</strong><strong>RingIPCHelper.setRingSeparateButton(this, false);//button touchpad一体
</strong></code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rayneo.gitbook.io/rayneo-devdoc/x-xi-lie/android-kai-fa/ipc-sdk/jie-zhi-shi-yong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
