16秒时间延迟,直到识别出蓝牙断开请求

use*_*021 6 android bluetooth

我正在使用蓝牙设备(IOIO开发板).

当我的设备断开连接时,我想听.它可以正常使用上面的代码,但它无法立即识别.当我关闭我的蓝牙开发板时,我必须等待~16秒,直到我的Android识别出连接丢失.

有人知道为什么吗?我听说应该是内部的Android限制,连接不经常检查?有人知道如何编写一个"ping"蓝牙设备的线程吗?我认为它与Android BluetoothChat示例非常相似,但我无法自行修复它.

谢谢.

费利克斯

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
    IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    this.registerReceiver(mReceiver, filter1);
    this.registerReceiver(mReceiver, filter2);
Run Code Online (Sandbox Code Playgroud)

}

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 (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
              //Device is about to disconnect
              Toast.makeText(context,"The device is about to disconnect" , Toast.LENGTH_LONG).show();
          }
          else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
              //Device has disconnected
              Toast.makeText(context,"Device has disconnected" , Toast.LENGTH_LONG).show();
          }           
       } 
   };
Run Code Online (Sandbox Code Playgroud)