簡體   English   中英

如何檢查藍牙設備是否已連接

[英]how to check a bluetooth device is connected

我需要開發一個應用程序來檢查我的 Arduino 是否連接到藍牙應用程序。 我聽說為此我必須制作一個自動藍牙聊天應用程序,即藍牙應用程序應該每 1 分鍾發送一個字母“g”,而 arduino 應該檢查它是否每 1 分鍾收到一個字母“g”。

我可以在 android studio 中列出配對的設備,但我無法連接到配對的設備。 那么誰能幫我構建一個自動藍牙聊天應用程序?

if (!mBluetoothAdapter.isEnabled()) {
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

谷歌文檔

順便說一句,為了檢查設備是否支持藍牙,請使用此代碼(同一文檔):

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
    // Device does not support Bluetooth
}

而且,當然不要忘記請求許可: <uses-permission android:name="android.permission.BLUETOOTH" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM