【问题标题】:Listening for Bluetooth Status监听蓝牙状态
【发布时间】:2011-06-17 03:41:19
【问题描述】:

我正在编写一个代码来监听蓝牙设备是否断开连接,然后执行一些操作。我该怎么做呢?我还不确定我想在它之后放什么,我想我会先解决这个问题。希望我对这段代码没有完全错误,因为我是开发新手。这是我目前所拥有的:

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

           if (BluetoothAdapter.ACTION_ACL_DISCONNECTED.equals(action))
           { // This will be the followup action, once I figure out what I want it to be.

【问题讨论】:

    标签: android bluetooth


    【解决方案1】:

    首先,使用BluetoothChat 示例开始,因为使用蓝牙进行编码非常复杂,而且有工作代码很好。您要查看的是 BluetoothChat.java 中的 handleMessage(),您需要保存状态。当状态从 BluetoothChatService.STATE_CONNECTED 变为 BluetoothChatService.STATE_NONE 时,设备已断开连接。

    【讨论】:

      猜你喜欢
      • 2015-04-11
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多