2012-05-03 45 views
2

我想知道是否有任何方法可以简单地检查蓝牙设备当前是否连接 - 我不想使用广播接收器 - 只需检查状态。我似乎无法弄清楚这是如何完成的。找到没有广播接收器的蓝牙状态?

我现在有一个听众,做听与蓝牙状态变化,并相应地改变内部变量 - 但是,即使它听起来不可思议只是说,它实际上似乎错过了蓝牙设备断开广播有时。我想要做的是运行额外的检查,看看设备是否真的仍然连接,或者如果广播被错过...

那么,我该怎么做?

感谢您的阅读/帮助!

+0

什么都没有?没有人?磕碰? – raingod

回答

0

我用它来检查蓝牙的状态。我不知道如何检查当前是否连接到其他设备,但我认为这可能是一个起点。

private void CheckBlueToothState() { 
    if (bluetoothAdapter == null) { 
     //stateBluetooth.setText("Bluetooth NOT support"); 
    } else { 
     if (bluetoothAdapter.isEnabled()) { 
      if (bluetoothAdapter.isDiscovering()) { 
       //stateBluetooth.setText("Bluetooth is currently in device discovery process."); 
      } else { 
       //stateBluetooth.setText("Bluetooth is Enabled."); 
      } 
     } else { 
      //stateBluetooth.setText("Bluetooth is NOT Enabled!"); 
      Intent enableBtIntent = new Intent(
        BluetoothAdapter.ACTION_REQUEST_ENABLE); 
      startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 
     } 
    } 
}