{"id":316818,"date":"2021-01-22T21:00:39","date_gmt":"2021-01-22T21:00:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=316818"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=316818","title":{"rendered":"Android Bluetooth Low Energy (BLE) \u2013 \u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0447\u0430\u0441\u0442\u044c #3 (read\/write)"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h4>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h4>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/536392\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c #1 (scanning)<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/537526\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c #2 (connecting\/disconnecting)<\/a><\/p>\n<p>\u0427\u0430\u0441\u0442\u044c #3 (read\/write), \u0432\u044b \u0437\u0434\u0435\u0441\u044c<\/p>\n<p>\u0412&nbsp;<a href=\"https:\/\/fmaxx.github.io\/android\/ble\/bluetoothlowenergy\/2020\/01\/10\/android-ble-part-2.html\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>&nbsp;\u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438\/\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 BLE \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e&nbsp;<strong>\u0447\u0442\u0435\u043d\u0438\u0438<\/strong>&nbsp;\u0438&nbsp;<strong>\u0437\u0430\u043f\u0438\u0441\u0438<\/strong>&nbsp;\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435&nbsp;<strong>\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438-\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/strong>.<\/p>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a<\/h3>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 BLE \u043d\u0430 Android, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 BLE \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a. \u041d\u0430&nbsp;<a href=\"https:\/\/stackoverflow.com\/search?q=android+ble+reading+writing+characteristic\" rel=\"noopener noreferrer nofollow\">Stackoverflow<\/a>&nbsp;\u043f\u043e\u043b\u043d\u043e \u043b\u044e\u0434\u0435\u0439, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438\u2026 \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p><strong>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435<\/strong>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0436\u0435 \u2013 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043b\u0431\u0435\u043a\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440&nbsp;<code>onCharacteristicRead()<\/code>&nbsp;\u0438\u043b\u0438&nbsp;<code>onCharacteristicWrite()<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f<\/strong>. \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0438 \u0437\u0430\u0442\u0435\u043c, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. \u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435&nbsp;<code>BluetoothGatt<\/code>&nbsp;\u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f. Google \u0437\u0430\u0431\u044b\u043b\u0430 \u043f\u0440\u043e \u044d\u0442\u043e \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\u2026 (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e&nbsp;<\/em><code>mDeviceBusy<\/code>&nbsp;\u0438&nbsp;<code>mDeviceBusyLock<\/code><a href=\"https:\/\/android.googlesource.com\/platform\/frameworks\/base\/+\/master\/core\/java\/android\/bluetooth\/BluetoothGatt.java\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0442\u0430\u043a\u043e\u0432\u0430 \u043f\u0440\u0438\u0440\u043e\u0434\u0430 BLE. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430&nbsp;<code>BluetoothGatt.java<\/code>&nbsp;\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>mDeviceBusy<\/code>, \u043f\u0435\u0440\u0435\u0434 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438:<\/p>\n<pre><code class=\"java\">public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {     if ((characteristic.getProperties()              &amp; BluetoothGattCharacteristic.PROPERTY_READ) == 0) {         return false;     }      if (VDBG) Log.d(TAG, \"readCharacteristic() - uuid: \" + characteristic.getUuid());     if (mService == null || mClientIf == 0) return false;      BluetoothGattService service = characteristic.getService();     if (service == null) return false;      BluetoothDevice device = service.getDevice();     if (device == null) return false;      synchronized (mDeviceBusy) {         if (mDeviceBusy) return false;         mDeviceBusy = true;     }      try {         mService.readCharacteristic(mClientIf, device.getAddress(),                 characteristic.getInstanceId(), AUTHENTICATION_NONE);     } catch (RemoteException e) {         Log.e(TAG, \"\", e);         mDeviceBusy = false;         return false;     }      return true; }<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>mDeviceBusy<\/code>&nbsp;\u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 false \u0441\u043d\u043e\u0432\u0430:<\/p>\n<pre><code class=\"java\">public void onCharacteristicRead(String address,                                  int status,                                  int handle,                                  byte[] value) {     if (VDBG) {         Log.d(TAG, \"onCharacteristicRead() - Device=\" + address                 + \" handle=\" + handle + \" Status=\" + status);     }      if (!address.equals(mDevice.getAddress())) {         return;     }      synchronized (mDeviceBusy) {         mDeviceBusy = false;     } ....<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/h3>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435\/\u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430 \u0440\u0430\u0437 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u043b\u044e\u0431\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u044d\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435&nbsp;<strong>\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a\u043e\u043c\u0430\u043d\u0434<\/strong>. \u0412\u0441\u0435 BLE \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0440\u0430\u043d\u0435\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b, \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u042d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a! \u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2013 \u043a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0417\u0430\u0442\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u00ab\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u0430\u044f\u00bb \u0438, \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u043e \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0434 BLE. \u0412 iOS \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a&nbsp;<code>CoreBluetooth<\/code>&nbsp;(<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0447\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Bluetooth \u0441\u0442\u0435\u043a\u0430 \u0432 Android<\/em>).<\/p>\n<p>\u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430&nbsp;<code>BluetoothGatt<\/code>. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Android \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432&nbsp;<code>BluetoothGatt<\/code>, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u0443 \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u043e\u043c\u0430\u043d\u0434 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432<\/em>). \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c&nbsp;<code>Queue<\/code>&nbsp;\u0441&nbsp;<code>Runnable<\/code>&nbsp;\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>commandQueueBusy<\/code>\u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"java\">private Queue&lt;Runnable&gt; commandQueue; private boolean commandQueueBusy;<\/code><\/pre>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440&nbsp;<code>Runnable<\/code>&nbsp;\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u0435\u043d\u0438\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 (readCharacteristic):<\/p>\n<pre><code class=\"java\">public boolean readCharacteristic(final BluetoothGattCharacteristic characteristic) {     if(bluetoothGatt == null) {         Log.e(TAG, \"ERROR: Gatt is 'null', ignoring read request\");         return false;     }      \/\/ Check if characteristic is valid     if(characteristic == null) {         Log.e(TAG, \"ERROR: Characteristic is 'null', ignoring read request\");         return false;     }      \/\/ Check if this characteristic actually has READ property     if((characteristic.getProperties() &amp; PROPERTY_READ) == 0 ) {         Log.e(TAG, \"ERROR: Characteristic cannot be read\");         return false;     }      \/\/ Enqueue the read command now that all checks have been passed     boolean result = commandQueue.add(new Runnable() {         @Override         public void run() {             if(!bluetoothGatt.readCharacteristic(characteristic)) {                 Log.e(TAG, String.format(\"ERROR: readCharacteristic failed for characteristic: %s\", characteristic.getUuid()));                 completedCommand();             } else {                 Log.d(TAG, String.format(\"reading characteristic &lt;%s&gt;\", characteristic.getUuid()));                 nrTries++;             }         }     });      if(result) {         nextCommand();     } else {         Log.e(TAG, \"ERROR: Could not enqueue read characteristic command\");     }     return result; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0441\u0435 \u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0438 \u0442\u0438\u043f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438) \u0438 \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c. \u0412\u043d\u0443\u0442\u0440\u0438&nbsp;<code>Runnable<\/code>, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434&nbsp;<code>readCharacteristic()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0430\u044f \u0442\u0430\u043a\u0442\u0438\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c<\/em>). \u0415\u0441\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442&nbsp;<code>false<\/code>, \u043c\u044b \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u00ab\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c\u00bb \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. \u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f&nbsp;<code>nextCommand()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"java\">private void nextCommand() {     \/\/ If there is still a command being executed then bail out     if(commandQueueBusy) {         return;     }      \/\/ Check if we still have a valid gatt object     if (bluetoothGatt == null) {         Log.e(TAG, String.format(\"ERROR: GATT is 'null' for peripheral '%s', clearing command queue\", getAddress()));         commandQueue.clear();         commandQueueBusy = false;         return;     }      \/\/ Execute the next command in the queue     if (commandQueue.size() &gt; 0) {         final Runnable bluetoothCommand = commandQueue.peek();         commandQueueBusy = true;         nrTries = 0;          bleHandler.post(new Runnable() {             @Override             public void run() {                     try {                         bluetoothCommand.run();                     } catch (Exception ex) {                         Log.e(TAG, String.format(\"ERROR: Command exception for device '%s'\", getName()), ex);                     }             }         });     } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434&nbsp;<code>peek()<\/code>&nbsp;\u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430&nbsp;<code>Runnable<\/code>&nbsp;\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0437\u0436\u0435. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0430\u0448 \u043a\u043e\u043b\u0431\u0435\u043a:<\/p>\n<pre><code class=\"java\">@Override public void onCharacteristicRead(BluetoothGatt gatt,                                  final BluetoothGattCharacteristic characteristic,                                  int status) {     \/\/ Perform some checks on the status field     if (status != GATT_SUCCESS) {         Log.e(TAG, String.format(Locale.ENGLISH,\"ERROR: Read failed for characteristic: %s, status %d\", characteristic.getUuid(), status));         completedCommand();         return;     }      \/\/ Characteristic has been read so processes it        ...     \/\/ We done, complete the command     completedCommand(); }<\/code><\/pre>\n<p>\u041c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443&nbsp;<code>completedCommand()<\/code>&nbsp;\u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0443\u0431\u0438\u0440\u0430\u0435\u043c&nbsp;<code>Runnable<\/code>&nbsp;\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432&nbsp;<code>poll()<\/code>&nbsp;\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"java\">private void completedCommand() {     commandQueueBusy = false;     isRetrying = false;     commandQueue.poll();     nextCommand(); }<\/code><\/pre>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 (\u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435), \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<code>Runnable<\/code>&nbsp;\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430&nbsp;<code>completedCommand()<\/code>. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0439\u0442\u0438 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043b\u0438\u043c\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"java\">private void retryCommand() {     commandQueueBusy = false;     Runnable currentCommand = commandQueue.peek();     if(currentCommand != null) {         if (nrTries &gt;= MAX_TRIES) {             \/\/ Max retries reached, give up on this one and proceed             Log.v(TAG, \"Max number of tries reached\");             commandQueue.poll();         } else {             isRetrying = true;         }     }     nextCommand(); }<\/code><\/pre>\n<h3>\u0417\u0430\u043f\u0438\u0441\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a<\/h3>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c&nbsp;<strong>\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0443<\/strong>,&nbsp;<strong>\u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0430\u0439\u0442\u043e\u0432<\/strong>&nbsp;\u0438&nbsp;<strong>\u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438<\/strong>. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438, \u0432\u0430\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0441 \u044d\u0442\u043e:<\/p>\n<ul>\n<li>\n<p><code>WRITE_TYPE_DEFAULT<\/code>&nbsp;(\u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f);<\/p>\n<\/li>\n<li>\n<p><code>WRITE_TYPE_NO_RESPONSE<\/code>&nbsp;(\u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442).<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0442\u0438\u043f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 (\u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0430 \u0442\u0438\u043f\u0430 \u0437\u0430\u043f\u0438\u0441\u0438, \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0442\u0438\u043f).<\/p>\n<p>\u0412 Android \u043a\u0430\u0436\u0434\u0430\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u041d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 Android, \u0433\u0434\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f:<\/p>\n<pre><code class=\"java\">... if ((mProperties &amp; PROPERTY_WRITE_NO_RESPONSE) != 0) {     mWriteType = WRITE_TYPE_NO_RESPONSE; } else {     mWriteType = WRITE_TYPE_DEFAULT; } ...<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0445 \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438. \u0415\u0441\u043b\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0430 \u0442\u0438\u043f\u0430, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442&nbsp;<code>WRITE_TYPE_NO_RESPONSE<\/code>. \u0418\u043c\u0435\u0439\u0442\u0435 \u044d\u0442\u043e \u0432\u0432\u0438\u0434\u0443!<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0443, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u0438 \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"java\">\/\/ Check if this characteristic actually supports this writeType int writeProperty; switch (writeType) {     case WRITE_TYPE_DEFAULT: writeProperty = PROPERTY_WRITE; break;     case WRITE_TYPE_NO_RESPONSE : writeProperty = PROPERTY_WRITE_NO_RESPONSE; break;     case WRITE_TYPE_SIGNED : writeProperty = PROPERTY_SIGNED_WRITE; break;     default: writeProperty = 0; break; } if((characteristic.getProperties() &amp; writeProperty) == 0 ) {     Log.e(TAG, String.format(Locale.ENGLISH,\"ERROR: Characteristic &lt;%s&gt; does not support writeType '%s'\", characteristic.getUuid(), writeTypeToString(writeType)));     return false; }<\/code><\/pre>\n<p>\u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 Android!<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0430\u0439\u0442\u043e\u0432&nbsp;<code>bytesToWrite<\/code>&nbsp;\u0432 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">characteristic.setValue(bytesToWrite); characteristic.setWriteType(writeType); if (!bluetoothGatt.writeCharacteristic(characteristic)) {     Log.e(TAG, String.format(\"ERROR: writeCharacteristic failed for characteristic: %s\", characteristic.getUuid()));     completedCommand(); } else {     Log.d(TAG, String.format(\"writing &lt;%s&gt; to characteristic &lt;%s&gt;\", bytes2String(bytesToWrite), characteristic.getUuid()));     nrTries++; }<\/code><\/pre>\n<h3>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\/\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. \u041f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442 \u0432\u0430\u043c \u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0438\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438 \u0432 Android:<\/p>\n<ol>\n<li>\n<p>\u0432\u044b\u0437\u0432\u0430\u0442\u044c&nbsp;<code>setCharacteristicNotification<\/code>. Bluetooth \u0441\u0442\u0435\u043a \u0431\u0443\u0434\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c&nbsp;<strong>1<\/strong>&nbsp;\u0438\u043b\u0438&nbsp;<strong>2<\/strong>&nbsp;\u043a\u0430\u043a&nbsp;<code>unsigned int16<\/code>&nbsp;\u0432 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a (Client Characteristic Configuration, \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e &#8212; \u0421\u0421\u0421). \u0414\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 CCC \u0438\u043c\u0435\u0435\u0442 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 UUID&nbsp;<strong>2902<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443&nbsp;<strong>1<\/strong>&nbsp;\u0438\u043b\u0438&nbsp;<strong>2<\/strong>? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c\u00bb Bluetooth \u0441\u0442\u0435\u043a\u0430 \u0435\u0441\u0442\u044c \u0423\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438 \u0418\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u044f. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0423\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0435\u043a\u043e\u043c Bluetooth, \u0430 \u0418\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u2013 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043a\u043e\u043c. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0418\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u0438, \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f Android \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u044b: \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0430\u0439\u0442\u043e\u0432 \u0438 Bluetooth \u0441\u0442\u0435\u043a \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043e\u0431 \u044d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0418\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u044e. \u0418\u0442\u0430\u043a,&nbsp;<strong>1<\/strong>&nbsp;\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f,&nbsp;<strong>2<\/strong>&nbsp;\u2013 \u0438\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c&nbsp;<strong>0<\/strong>. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 CCC.<\/p>\n<p>\u0412 iOS \u043c\u0435\u0442\u043e\u0434&nbsp;<code>setNotify()<\/code>&nbsp;\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430 \u0432\u0430\u0441. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430 Android, \u0442\u0430\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0434\u0443\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<pre><code class=\"java\">private final String CCC_DESCRIPTOR_UUID = \"00002902-0000-1000-8000-00805f9b34fb\"; public boolean setNotify(BluetoothGattCharacteristic characteristic,                          final boolean enable) {     \/\/ Check if characteristic is valid     if(characteristic == null) {         Log.e(TAG, \"ERROR: Characteristic is 'null', ignoring setNotify request\");         return false;     }      \/\/ Get the CCC Descriptor for the characteristic     final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(CCC_DESCRIPTOR_UUID));     if(descriptor == null) {         Log.e(TAG, String.format(\"ERROR: Could not get CCC descriptor for characteristic %s\", characteristic.getUuid()));         return false;     }      \/\/ Check if characteristic has NOTIFY or INDICATE properties and set the correct byte value to be written     byte[] value;     int properties = characteristic.getProperties();     if ((properties &amp; PROPERTY_NOTIFY) &gt; 0) {         value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;     } else if ((properties &amp; PROPERTY_INDICATE) &gt; 0) {         value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;     } else {         Log.e(TAG, String.format(\"ERROR: Characteristic %s does not have notify or indicate property\", characteristic.getUuid()));         return false;     }     final byte[] finalValue = enable ? value : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;      \/\/ Queue Runnable to turn on\/off the notification now that all checks have been passed     boolean result = commandQueue.add(new Runnable() {         @Override         public void run() {             \/\/ First set notification for Gatt object  if(!bluetoothGatt.setCharacteristicNotification(descriptor.getCharacteristic(), enable)) {                 Log.e(TAG, String.format(\"ERROR: setCharacteristicNotification failed for descriptor: %s\", descriptor.getUuid()));             }              \/\/ Then write to descriptor             descriptor.setValue(finalValue);             boolean result;             result = bluetoothGatt.writeDescriptor(descriptor);             if(!result) {                 Log.e(TAG, String.format(\"ERROR: writeDescriptor failed for descriptor: %s\", descriptor.getUuid()));                 completedCommand();             } else {                 nrTries++;             }         }     });      if(result) {         nextCommand();     } else {         Log.e(TAG, \"ERROR: Could not enqueue write command\");     }      return result; }<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 CCC \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u0431\u0435\u043a\u0435&nbsp;<code>onDescriptorWrite<\/code>. \u0417\u0434\u0435\u0441\u044c \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 CCC \u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043b\u0431\u0435\u043a\u0430, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u044e\u0442\u0441\u044f.<\/p>\n<pre><code class=\"java\">@Override public void onDescriptorWrite(BluetoothGatt gatt,                                  final BluetoothGattDescriptor descriptor,                                  final int status) {     \/\/ Do some checks first     final BluetoothGattCharacteristic parentCharacteristic = descriptor.getCharacteristic();     if(status!= GATT_SUCCESS) {         Log.e(TAG, String.format(\"ERROR: Write descriptor failed value &lt;%s&gt;, device: %s, characteristic: %s\", bytes2String(currentWriteBytes), getAddress(), parentCharacteristic.getUuid()));     }      \/\/ Check if this was the Client Configuration Descriptor  if(descriptor.getUuid().equals(UUID.fromString(CCC_DESCRIPTOR_UUID))) {         if(status==GATT_SUCCESS) {             \/\/ Check if we were turning notify on or off             byte[] value = descriptor.getValue();             if (value != null) {                 if (value[0] != 0) {                     \/\/ Notify set to on, add it to the set of notifying characteristics          notifyingCharacteristics.add(parentCharacteristic.getUuid());                     }                 } else {                     \/\/ Notify was turned off, so remove it from the set of notifying characteristics               notifyingCharacteristics.remove(parentCharacteristic.getUuid());                 }             }         }         \/\/ This was a setNotify operation         ....     } else {         \/\/ This was a normal descriptor write....         ...         });     }     completedCommand(); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u0437 \u043a\u0430\u043a\u043e\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u0440\u0438\u0448\u043b\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434&nbsp;<code>isNotifying()<\/code>:<\/p>\n<pre><code class=\"java\">public boolean isNotifying(BluetoothGattCharacteristic characteristic) {     return notifyingCharacteristics.contains(characteristic.getUuid()); }<\/code><\/pre>\n<h3>\u041b\u0438\u043c\u0438\u0442\u044b \u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0447\u0435\u0448\u044c. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Android-5 \u043b\u0438\u043c\u0438\u0442 \u0440\u0430\u0432\u0435\u043d 15. \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043e\u043d \u0431\u044b\u043b \u0440\u0430\u0432\u0435\u043d 7 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 4. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d\u043e\u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 15 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0445, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0442\u044c \u043b\u0438\u043c\u0438\u0442.<\/p>\n<h3>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/h3>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0447\u0438\u0442\u0430\u0442\u044c\/\u043f\u0438\u0441\u0430\u0442\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\/\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0433\u043e\u0442\u043e\u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 BLE \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u0440\u043c\u043e\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 Bluetooth Health Thermometer \u0441\u0435\u0440\u0432\u0438\u0441. \u0422\u0430\u043a\u0438\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0442\u044c. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430;<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0436\u043d\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/strong>. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u0432\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0427\u0430\u0441\u0442\u043e \u044d\u0442\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u044b \u043d\u0435 \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0434 BLE, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0432 BLE, \u0433\u0434\u0435 \u043e\u0434\u043d\u0430 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u0430\u043d\u0434 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c: \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u0430\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u2013 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0427\u0442\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0443\u0442 \u0447\u0435\u0440\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043c\u043e\u0433\u0443\u0442 \u043c\u0435\u0448\u0430\u0442\u044c \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (30Hz \u0438\u043b\u0438 \u043e\u043a\u043e\u043b\u043e).<\/p>\n<p>\u0422\u0438\u043f\u0438\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432&nbsp;<code>BluetoothGattCharacteristic<\/code><\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0432\u0430\u0448\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f, \u0432\u044b \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0442\u0435\u0440\u044f\u0435\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><strong>\u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e, Android \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/strong>&nbsp;(\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0435\u0441\u0442\u044c). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0438 Android \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>Android&nbsp;<strong>\u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 BluetoothGattCharacteristic \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438<\/strong>. \u041e\u043d\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 (services discovering) \u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e&nbsp;<strong>\u043f\u0435\u0440\u0435\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f<\/strong>\u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f Android \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<code>BluetoothGattCharacteristic<\/code>. \u0415\u0441\u043b\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0433\u043e\u043d\u043a\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (race condition) \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e&nbsp;<strong>\u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043e\u043f\u0438\u0435\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0430\u0439\u0442\u043e\u0432<\/strong>. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043e\u043f\u0438\u044e \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0435\u0439.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0442\u0430\u043a\u0442\u0438\u043a\u0443:<\/p>\n<pre><code class=\"java\">@Override public void onCharacteristicChanged(BluetoothGatt gatt,                                      final BluetoothGattCharacteristic characteristic) {     \/\/ Copy the byte array so we have a threadsafe copy     final byte[] value = new byte[characteristic.getValue().length];     System.arraycopy(         characteristic.getValue(),          0, value, 0,          characteristic.getValue().length);      \/\/ Characteristic has new value so pass it on for processing     bleHandler.post(new Runnable() {         @Override         public void run() {                      myProcessor.onCharacteristicUpdate(BluetoothPeripheral.this, value, characteristic);         }     }); }<\/code><\/pre>\n<h3>\u0414\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/h3>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 BLE \u043d\u0430 Android. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0435\u043a BLE \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0443\u043b\u044c\u0442\u0438-\u043f\u043e\u0442\u043e\u0447\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>Android \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0432&nbsp;<code>main<\/code>&nbsp;\u043f\u043e\u0442\u043e\u043a);<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043b\u0431\u0435\u043a\u043e\u0432&nbsp;<code>BluetoothGattCallback<\/code>&nbsp;(\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043a\u0430\u0445&nbsp;<code>Binder<\/code>);<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 main \u043f\u043e\u0442\u043e\u043a\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u041d\u043e \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 Binder \u0432\u0441\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0435 Binder, Android \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0445, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0442\u043e\u043a Binder \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430 \u0432\u0430\u0448 \u043a\u043e\u0434 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0442\u044f\u0436\u0435\u043b\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u043a\u043e\u043b\u0431\u0435\u043a\u0430\u0445, \u043d\u0438\u043a\u0430\u043a\u0438\u0445&nbsp;<code>sleep()<\/code>&nbsp;\u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435&nbsp;<code>BluetoothGatt<\/code>, \u043f\u043e\u043a\u0430 \u0432\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435\u0441\u044c \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 Binder, \u0445\u043e\u0442\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435.<\/p>\n<p>\u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0439\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u044b&nbsp;<code>BluetoothGattCallback<\/code>&nbsp;\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, &nbsp;\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 main \u043f\u043e\u0442\u043e\u043a\u0435 &#8212; \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u0434\u0435\u044f, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043e\u0431\u043c\u0435\u043d \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043b\u0438\u043f\u0430\u043d\u0438\u044f UI, \u043d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u0430\u043a)<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0439\u0442\u0435 \u043f\u043e\u0442\u043e\u043a\u0438&nbsp;<code>Binder<\/code>&nbsp;\u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438&nbsp;<strong>\u043d\u0438\u043a\u043e\u0433\u0434\u0430<\/strong>&nbsp;\u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0445;<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u0435 \u2013 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439&nbsp;<code>Handler<\/code>&nbsp;\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u044b\u0434\u0430\u0447\u0438 \u043d\u043e\u0432\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u044f \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b&nbsp;<code>Handler<\/code>&nbsp;\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043a\u043e\u043b\u0431\u0435\u043a\u0430&nbsp;<code>onCharacteristicUpdate<\/code>.<\/p>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"java\">Handler bleHandler = new Handler();<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c&nbsp;<code>Handler<\/code>&nbsp;\u043d\u0430&nbsp;<code>main<\/code>&nbsp;\u043f\u043e\u0442\u043e\u043a\u0435:<\/p>\n<pre><code class=\"java\">Handler bleHandler = new Handler(Looper.getMainLooper());<\/code><\/pre>\n<p>\u041f\u0440\u043e\u043a\u0440\u0443\u0442\u0438\u0442\u0435 \u043d\u0430\u0437\u0430\u0434 \u0438 \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434&nbsp;<code>nextCommand()<\/code>, \u043a\u0430\u0436\u0434\u044b\u0439&nbsp;<code>Runnable<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c&nbsp;<code>Handler<\/code>, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0435 \u043f\u043e\u0442\u043e\u043a\u0430&nbsp;<code>Binder<\/code>.<\/p>\n<h3>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f: \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 (bonding)<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439\/\u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u044b \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u044f \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c (bonding).<\/p>\n<blockquote>\n<p><em>\u041d\u0435 \u0442\u0435\u0440\u043f\u0438\u0442\u0441\u044f \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 BLE? \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435&nbsp;<\/em><a href=\"https:\/\/github.com\/weliem\/blessed-android\" rel=\"noopener noreferrer nofollow\"><em>\u043c\u043e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Blessed for Android<\/em><\/a><em>. \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 BLE \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/em><\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/538768\/\"> https:\/\/habr.com\/ru\/post\/538768\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h4>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h4>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/536392\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c #1 (scanning)<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/537526\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c #2 (connecting\/disconnecting)<\/a><\/p>\n<p>\u0427\u0430\u0441\u0442\u044c #3 (read\/write), \u0432\u044b \u0437\u0434\u0435\u0441\u044c<\/p>\n<p>\u0412&nbsp;<a href=\"https:\/\/fmaxx.github.io\/android\/ble\/bluetoothlowenergy\/2020\/01\/10\/android-ble-part-2.html\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>&nbsp;\u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438\/\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 BLE \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e&nbsp;<strong>\u0447\u0442\u0435\u043d\u0438\u0438<\/strong>&nbsp;\u0438&nbsp;<strong>\u0437\u0430\u043f\u0438\u0441\u0438<\/strong>&nbsp;\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435&nbsp;<strong>\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438-\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/strong>.<\/p>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a<\/h3>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 BLE \u043d\u0430 Android, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 BLE \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a. \u041d\u0430&nbsp;<a href=\"https:\/\/stackoverflow.com\/search?q=android+ble+reading+writing+characteristic\" rel=\"noopener noreferrer nofollow\">Stackoverflow<\/a>&nbsp;\u043f\u043e\u043b\u043d\u043e \u043b\u044e\u0434\u0435\u0439, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438\u2026 \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p><strong>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435<\/strong>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0436\u0435 \u2013 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043b\u0431\u0435\u043a\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440&nbsp;<code>onCharacteristicRead()<\/code>&nbsp;\u0438\u043b\u0438&nbsp;<code>onCharacteristicWrite()<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f<\/strong>. \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0438 \u0437\u0430\u0442\u0435\u043c, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. \u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435&nbsp;<code>BluetoothGatt<\/code>&nbsp;\u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f. Google \u0437\u0430\u0431\u044b\u043b\u0430 \u043f\u0440\u043e \u044d\u0442\u043e \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\u2026 (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e&nbsp;<\/em><code>mDeviceBusy<\/code>&nbsp;\u0438&nbsp;<code>mDeviceBusyLock<\/code><a href=\"https:\/\/android.googlesource.com\/platform\/frameworks\/base\/+\/master\/core\/java\/android\/bluetooth\/BluetoothGatt.java\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0442\u0430\u043a\u043e\u0432\u0430 \u043f\u0440\u0438\u0440\u043e\u0434\u0430 BLE. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430&nbsp;<code>BluetoothGatt.java<\/code>&nbsp;\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>mDeviceBusy<\/code>, \u043f\u0435\u0440\u0435\u0434 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438:<\/p>\n<pre><code class=\"java\">public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {     if ((characteristic.getProperties()              &amp; BluetoothGattCharacteristic.PROPERTY_READ) == 0) {         return false;     }      if (VDBG) Log.d(TAG, \"readCharacteristic() - uuid: \" + characteristic.getUuid());     if (mService == null || mClientIf == 0) return false;      BluetoothGattService service = characteristic.getService();     if (service == null) return false;      BluetoothDevice device = service.getDevice();     if (device == null) return false;      synchronized (mDeviceBusy) {         if (mDeviceBusy) return false;         mDeviceBusy = true;     }      try {         mService.readCharacteristic(mClientIf, device.getAddress(),                 characteristic.getInstanceId(), AUTHENTICATION_NONE);     } catch (RemoteException e) {         Log.e(TAG, \"\", e);         mDeviceBusy = false;         return false;     }      return true; }<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>mDeviceBusy<\/code>&nbsp;\u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 false \u0441\u043d\u043e\u0432\u0430:<\/p>\n<pre><code class=\"java\">public void onCharacteristicRead(String address,                                  int status,                                  int handle,                                  byte[] value) {     if (VDBG) {         Log.d(TAG, \"onCharacteristicRead() - Device=\" + address                 + \" handle=\" + handle + \" Status=\" + status);     }      if (!address.equals(mDevice.getAddress())) {         return;     }      synchronized (mDeviceBusy) {         mDeviceBusy = false;     } ....<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/h3>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435\/\u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430 \u0440\u0430\u0437 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u043b\u044e\u0431\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u044d\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435&nbsp;<strong>\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a\u043e\u043c\u0430\u043d\u0434<\/strong>. \u0412\u0441\u0435 BLE \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0440\u0430\u043d\u0435\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b, \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u042d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a! \u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2013 \u043a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0417\u0430\u0442\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u00ab\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u0430\u044f\u00bb \u0438, \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u043e \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0434 BLE. \u0412 iOS \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a&nbsp;<code>CoreBluetooth<\/code>&nbsp;(<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0447\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Bluetooth \u0441\u0442\u0435\u043a\u0430 \u0432 Android<\/em>).<\/p>\n<p>\u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430&nbsp;<code>BluetoothGatt<\/code>. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Android \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432&nbsp;<code>BluetoothGatt<\/code>, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u0443 \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u043e\u043c\u0430\u043d\u0434 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432<\/em>). \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c&nbsp;<code>Queue<\/code>&nbsp;\u0441&nbsp;<code>Runnable<\/code>&nbsp;\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>commandQueueBusy<\/code>\u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"java\">private Queue&lt;Runnable&gt; commandQueue; private boolean commandQueueBusy;<\/code><\/pre>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440&nbsp;<code>Runnable<\/code>&nbsp;\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u0435\u043d\u0438\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 (readCharacteristic):<\/p>\n<pre><code class=\"java\">public boolean readCharacteristic(final BluetoothGattCharacteristic characteristic) {     if(bluetoothGatt == null) {         Log.e(TAG, \"ERROR: Gatt is 'null', ignoring read request\");         return false;     }      \/\/ Check if characteristic is valid     if(characteristic == null) {         Log.e(TAG, \"ERROR: Characteristic is 'null', ignoring read request\");         return false;     }      \/\/ Check if this characteristic actually has READ property     if((characteristic.getProperties() &amp; PROPERTY_READ) == 0 ) {         Log.e(TAG, \"ERROR: Characteristic cannot be read\");         return false;     }      \/\/ Enqueue the read command now that all checks have been passed     boolean result = commandQueue.add(new Runnable() {         @Override         public void run() {             if(!bluetoothGatt.readCharacteristic(characteristic)) {                 Log.e(TAG, String.format(\"ERROR: readCharacteristic failed for characteristic: %s\", characteristic.getUuid()));                 completedCommand();             } else {                 Log.d(TAG, String.format(\"reading characteristic &lt;%s&gt;\", characteristic.getUuid()));                 nrTries++;             }         }     });      if(result) {         nextCommand();     } else {         Log.e(TAG, \"ERROR: Could not enqueue read characteristic command\");     }     return result; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0441\u0435 \u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0438 \u0442\u0438\u043f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438) \u0438 \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c. \u0412\u043d\u0443\u0442\u0440\u0438&nbsp;<code>Runnable<\/code>, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434&nbsp;<code>readCharacteristic()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (<em>\u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0430\u044f \u0442\u0430\u043a\u0442\u0438\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c<\/em>). \u0415\u0441\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442&nbsp;<code>false<\/code>, \u043c\u044b \u043b\u043e\u0433\u0433\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u00ab\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c\u00bb \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. \u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f&nbsp;<code>nextCommand()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"java\">private void nextCommand() {     \/\/ If there is still a command being executed then bail out     if(commandQueueBusy) {         return;     }      \/\/ Check if we still have a valid gatt object     if (bluetoothGatt == null) {         Log.e(TAG, String.format(\"ERROR: GATT is 'null' for peripheral '%s', clearing command queue\", getAddress()));         commandQueue.clear();         commandQueueBusy = false;         return;     }      \/\/ Execute the next command in the queue     if (commandQueue.size() &gt; 0) {         final Runnable bluetoothCommand = commandQueue.peek();         commandQueueBusy = true;         nrTries = 0;          bleHandler.post(new Runnable() {             @Override             public void run() {                     try {                         bluetoothCommand.run();                     } catch (Exception ex) {                         Log.e(TAG, String.format(\"ERROR: Command exception for device '%s'\", getName()), ex);                     }             }         });     } }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434&nbsp;<code>peek()<\/code>&nbsp;\u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430&nbsp;<code>Runnable<\/code>&nbsp;\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0437\u0436\u0435. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0430\u0448 \u043a\u043e\u043b\u0431\u0435\u043a:<\/p>\n<pre><code class=\"java\">@Override public void onCharacteristicRead(BluetoothGatt gatt,                                  final BluetoothGattCharacteristic characteristic,                                  int status) {     \/\/ Perform some checks on the status field     if (status != GATT_SUCCESS) {         Log.e(TAG, String.format(Locale.ENGLISH,\"ERROR: Read failed for characteristic: %s, status %d\", characteristic.getUuid(), status));         completedCommand();         return;     }      \/\/ Characteristic has been read so processes it        ...     \/\/ We done, complete the command     completedCommand(); }<\/code><\/pre>\n<p>\u041c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443&nbsp;<code>completedCommand()<\/code>&nbsp;\u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0443\u0431\u0438\u0440\u0430\u0435\u043c&nbsp;<code>Runnable<\/code>&nbsp;\u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432&nbsp;<code>poll()<\/code>&nbsp;\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"java\">private void completedCommand() {     commandQueueBusy = false;     isRetrying = false;     commandQueue.poll();     nextCommand(); }<\/code><\/pre>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 (\u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435), \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<code>Runnable<\/code>&nbsp;\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430&nbsp;<code>completedCommand()<\/code>. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0439\u0442\u0438 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043b\u0438\u043c\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"java\">private void retryCommand() {     commandQueueBusy = false;     Runnable currentCommand = commandQueue.peek();     if(currentCommand != null) {         if (nrTries &gt;= MAX_TRIES) {             \/\/ Max retries reached, give up on this one and proceed             Log.v(TAG, \"Max number of tries reached\");             commandQueue.poll();         } else {             isRetrying = true;         }     }     nextCommand(); }<\/code><\/pre>\n<h3>\u0417\u0430\u043f\u0438\u0441\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a<\/h3>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c&nbsp;<strong>\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0443<\/strong>,&nbsp;<strong>\u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0430\u0439\u0442\u043e\u0432<\/strong>&nbsp;\u0438&nbsp;<strong>\u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438<\/strong>. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438, \u0432\u0430\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0441 \u044d\u0442\u043e:<\/p>\n<ul>\n<li>\n<p><code>WRITE_TYPE_DEFAULT<\/code>&nbsp;(\u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f);<\/p>\n<\/li>\n<li>\n<p><code>WRITE_TYPE_NO_RESPONSE<\/code>&nbsp;(\u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442).<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0442\u0438\u043f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 (\u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0430 \u0442\u0438\u043f\u0430 \u0437\u0430\u043f\u0438\u0441\u0438, \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0442\u0438\u043f).<\/p>\n<p>\u0412 Android \u043a\u0430\u0436\u0434\u0430\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u041d\u0438\u0436\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 Android, \u0433\u0434\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f:<\/p>\n<pre><code class=\"java\">... if<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-316818","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316818"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316818\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}