大佬教程收集整理的这篇文章主要介绍了android – 完全断开蓝牙低功耗设备,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我断开连接时,请使用以下内容:
private void disconnectDevice() { gatt.disconnect(); }
当我收到回调时,我会收尾.
private BluetoothGattCallBACk gattCallBACk = new BluetoothGattCallBACk() { @Override public void onConnectionStateChange(BluetoothGatt gatt,int status,int newStatE) { switch (newStatE) { case BluetoothProfile.STATE_CONNECTED: Log.d("BLED-GATT","STATE_CONNECTED"); setUIConnectionStatus("Discover services on device...",Color.YELLOW); checkEnableAddButton(simpleTrackEditText.getText().toString()); gatt.discoverservices(); break; case BluetoothProfile.STATE_DISCONNECTED: Log.d("BLED-GATT","STATE_DISCONNECTED"); setUIConnectionStatus("Not Connected!",Color.RED); gatt.close(); break; default: Log.d("BLED-GATT","STATE_OTHER"); } } }
这是执行的,我在调用disconnectDevice()后无法再控制设备.设备本身似乎认为它仍然连接,因为我无法将其置于广播可见性模式(如果它已经有连接就会发生).但是,如果我终止应用程序并再次打开它,那么我可以将设备设置为广播模式.这告诉我应用程序未正确断开连接.
知道我错过了什么吗?
/** * Connects to the device. Does nothing if already connected. * @param macAddress the address of the device. */ private void connectDevice(String macAddress) { if (!isConnected()) { device = bluetoothAdapter.getRemoteDevice(macAddress); if (device == null) { this.sendToast("Device Not Available"); } else { Log.d("BLED","ConnecTing..."); gatt = device.connectGatt(this,true,gattCallBACk); } } }
以上是大佬教程为你收集整理的android – 完全断开蓝牙低功耗设备全部内容,希望文章能够帮你解决android – 完全断开蓝牙低功耗设备所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。