# 手机连接状态 & GPS推流

手机连接状态主要是通过MobileState类来获取，MobileState.isMobileConnected()得到手机连接状态的数据流，可以实时监听手机的连接状态，实现方式如下：

<pre class="language-kotlin"><code class="lang-kotlin">private fun collectBleStatus() {
<strong>    MobileState.isMobileConnected().onEach {
</strong><strong>        FLogger.d("isMobileConnected:$it")
</strong><strong>        mBindingPair.updateView {
</strong><strong>            tvBleStatus.text = if (it) "connect" else "disconnect"
</strong><strong>        }
</strong><strong>    }.launchIn(lifecycleScope)
</strong>}
</code></pre>

\
获取连接手机的GPS推流需要先集成IPC SDK，集成方式可参考IPCSDK for Android，具体实现方式可参考IPC SDK Sample或者上述Sample中的APIActivity，需要注意的是onResponse回调在异步线程，需要关注线程切换：

<pre class="language-java"><code class="lang-java">private val response =
<strong>    OnResponseListener { response ->
</strong><strong>        if (response?.getData() == null) return@OnResponseListener
</strong>        try {
            val jo = JSONObject(response.getData())
            if (jo.has("mLatitude") &#x26;&#x26; jo.has("mLongitude") &#x26;&#x26; jo.has("mAltitude")) { //GPS数据
                val mProvider = jo.getString("mProvider")
                val mTime = jo.getLong("mTime")
                val mElapsedRealtimeNanos = jo.getLong("mElapsedRealtimeNanos")
                val mLatitude = jo.getDouble("mLatitude")
                val mLongitude = jo.getDouble("mLongitude")
<strong>                runOnUiThread {
</strong><strong>                    mBindingPair.updateView {
</strong><strong>                        tvTvLocationInfo.text = "$mLatitude,$mLongitude"
</strong><strong>                    }
</strong><strong>                }
</strong><strong>           
</strong>            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
<strong>    }
</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/neng-li-jie-shao/shou-ji-lian-jie-zhuang-tai-gps-tui-liu.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.
