当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGatt.GATT_SUCCESS属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothGatt.GATT_SUCCESS属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGatt.GATT_SUCCESS属性的具体用法?Java BluetoothGatt.GATT_SUCCESS怎么用?Java BluetoothGatt.GATT_SUCCESS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothGatt的用法示例。


在下文中一共展示了BluetoothGatt.GATT_SUCCESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onServicesDiscovered

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        for(BluetoothGattService service : gatt.getServices()){
            Log.d(mTAG, "service: " + service.getUuid().toString());
        }
        //Log.d(mTAG, "mGattMiFloraService: " + UUID_MI_FLORA_SERVICE_ID.toString());
        mGattMiFloraService = gatt.getService(UUID_MI_FLORA_SERVICE_ID);
        if(mGattMiFloraService != null){
            boolean rs = gatt.readCharacteristic(mGattMiFloraService.getCharacteristic(UUID_MI_FLORA_FIRMWARE));
            if(!rs){
                Log.i(mTAG, "Can't read mGattMiFloraFwCharacteristic");
            }
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:20,代码来源:MiFloraSensorEntity.java

示例2: onCharacteristicReadRequest

@Override
public void onCharacteristicReadRequest(
        BluetoothDevice device,
        int requestId,
        int offset,
        BluetoothGattCharacteristic chr) {
    int status = BluetoothGatt.GATT_FAILURE;
    byte[] bytes = null;

    if (offset != 0) {
        status = BluetoothGatt.GATT_INVALID_OFFSET;
    } else if (chr.equals(U2FGattService.U2F_CONTROL_POINT_LENGTH)) {
        status = BluetoothGatt.GATT_SUCCESS;
        bytes = new byte[] { 0x02, 0x00 }; /* Length == 512, see U2F BT 6.1 */
    } else if (chr.equals(U2FGattService.U2F_SERVICE_REVISION_BITFIELD)) {
        status = BluetoothGatt.GATT_SUCCESS;
        bytes = new byte[] { 0x40 };       /* Version == 1.2, see U2F BT 6.1 */
    }

    Log.d(getClass().getCanonicalName(), Integer.valueOf(bytes.length).toString());
    mGattServer.sendResponse(device, requestId, status, 0, bytes);
}
 
开发者ID:freeu2f,项目名称:freeu2f-android,代码行数:22,代码来源:U2FService.java

示例3: onCharacteristicRead

@Override
    public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
/*
 * This method is called when the DFU Version characteristic has been read.
 */
            sendLogBroadcast(LOG_LEVEL_INFO, "Read Response received from " + characteristic.getUuid() + ", value (0x): " + parse(characteristic));
            mReceivedData = characteristic.getValue();
            mRequestCompleted = true;
        } else {
            loge("Characteristic read error: " + status);
            mError = ERROR_CONNECTION_MASK | status;
        }

        // Notify waiting thread
        synchronized (mLock) {
            mLock.notifyAll();
        }
    }
 
开发者ID:Samsung,项目名称:microbit,代码行数:19,代码来源:DfuBaseService.java

示例4: onServicesDiscovered

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        getGattServices(getSupportedGattServices());
        broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); // broadcast Gatt connection state : discovered
    } else {
        Log.e(TAG, "onServicesDiscovered received: " + status);
    }
}
 
开发者ID:skydoves,项目名称:MagicLight-Controller,代码行数:9,代码来源:BluetoothLeService.java

示例5: onCharacteristicWrite

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
	super.onCharacteristicWrite(gatt, characteristic, status);

	if (writeCallback != null) {

		if (writeQueue.size() > 0){
			byte[] data = writeQueue.get(0);
			writeQueue.remove(0);
			doWrite(characteristic, data);
		} else {

			if (status == BluetoothGatt.GATT_SUCCESS) {
				writeCallback.invoke();
			} else {
				Log.e(LOG_TAG, "Error onCharacteristicWrite:" + status);
				writeCallback.invoke("Error writing status: " + status);
			}

			writeCallback = null;
		}
	}else
		Log.e(LOG_TAG, "No callback on write");
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:24,代码来源:Peripheral.java

示例6: onServicesDiscovered

/**
 * 服务被发现
 * 可以给特征符写入数据, 发送给BLE终端
 * @param gatt
 * @param status
 */
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        BleManager.connectionState = Constant.STATE_SERVICES_DISCOVERED;
        onServiceConnectSuccess(gatt, status);
    } else {
        Log.w(TAG, "onServicesDiscovered received: " + status);
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:15,代码来源:BleGattCallback.java

示例7: onServicesDiscovered

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    super.onServicesDiscovered(gatt, status);

    int state = BLE_SERVICES_DISCOVERED;

    synchronized(locker) {
        if(DEBUG) {
            logi("BluetoothGattCallback.onServicesDiscovered() :: start : status = " + status);
        }

        if(inBleOp == OP_DISCOVER_SERVICES) {
            if(DEBUG) {
                logi("BluetoothGattCallback.onServicesDiscovered() :: inBleOp == OP_DISCOVER_SERVICES");
            }

            if(status == BluetoothGatt.GATT_SUCCESS) {
                bleState |= state;

            } else {
                bleState &= (~state);
            }

            callbackCompleted = true;
            locker.notify();
        }

        if(DEBUG) {
            logi("BluetoothGattCallback.onServicesDiscovered() :: end");
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:32,代码来源:BLEManager.java

示例8: onCharacteristicWrite

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicWrite(gatt, characteristic, status);
    NLog.d("call onCharacteristicWrite status : " + status);
    if ( status == BluetoothGatt.GATT_SUCCESS)
    {
        mConnectionThread.continuousWrite();
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:9,代码来源:BTLEAdt.java

示例9: onCharacteristicWrite

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicWrite(gatt, characteristic, status);

    synchronized(locker) {
        if(DEBUG) {
            logi("BluetoothGattCallback.onCharacteristicWrite() :: start : status = " + status);
        }

        if(inBleOp == OP_WRITE_CHARACTERISTIC) {
            if(DEBUG) {
                logi("BluetoothGattCallback.onCharacteristicWrite() :: inBleOp == OP_WRITE_CHARACTERISTIC");
            }

            if(status == BluetoothGatt.GATT_SUCCESS) {
                error = BLE_ERROR_OK;
            } else {
                error = BLE_ERROR_FAIL;
            }

            lastCharacteristic = characteristic;
            callbackCompleted = true;
            locker.notify();
        }

        if(DEBUG) {
            logi("BluetoothGattCallback.onCharacteristicWrite() :: end");
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:30,代码来源:BLEManager.java

示例10: onDescriptorWrite

@Override
public final void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
	if (status == BluetoothGatt.GATT_SUCCESS) {
		Logger.i(mLogSession, "Data written to descr. " + descriptor.getUuid() + ", value: " + ParserUtils.parse(descriptor));

		if (isServiceChangedCCCD(descriptor)) {
			Logger.a(mLogSession, "Service Changed notifications enabled");
			if (!readBatteryLevel())
				nextRequest();
		} else if (isBatteryLevelCCCD(descriptor)) {
			final byte[] value = descriptor.getValue();
			if (value != null && value.length > 0 && value[0] == 0x01) {
				Logger.a(mLogSession, "Battery Level notifications enabled");
				nextRequest();
			} else
				Logger.a(mLogSession, "Battery Level notifications disabled");
		} else {
			nextRequest();
		}
	} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
		if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
			DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
			mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
		}
	} else {
		DebugLogger.e(TAG, "onDescriptorWrite error " + status);
		onError(ERROR_WRITE_DESCRIPTOR, status);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:29,代码来源:BleManager.java

示例11: parseConnectionError

/**
 * Converts the connection status given by the {@link android.bluetooth.BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} to error name.
 * @param error the status number
 * @return the error name as stated in the gatt_api.h file
 */
public static String parseConnectionError(final int error) {
	switch (error) {
		case BluetoothGatt.GATT_SUCCESS:
			return "SUCCESS";

		case 0x01:
			return "GATT CONN L2C FAILURE";

		case 0x08:
			return "GATT CONN TIMEOUT";

		case 0x13:
			return "GATT CONN TERMINATE PEER USER";

		case 0x16:
			return "GATT CONN TERMINATE LOCAL HOST";

		case 0x3E:
			return "GATT CONN FAIL ESTABLISH";

		case 0x22:
			return "GATT CONN LMP TIMEOUT";

		case 0x0100:
			return "GATT CONN CANCEL ";

		case 0x0085:
			return "GATT ERROR"; // Device not reachable

		default:
			return "UNKNOWN (" + error + ")";
	}
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:38,代码来源:GattError.java

示例12: testSuccessful

@Test
public void testSuccessful() {
    CommandResult result1 = new CommandResult(Neatle.createUUID(1), null, BluetoothGatt.GATT_SUCCESS, 0);
    CommandResult result2 = new CommandResult(Neatle.createUUID(2), null, BluetoothGatt.GATT_SUCCESS, 0);
    CommandResult result3 = new CommandResult(Neatle.createUUID(3), null, BluetoothGatt.GATT_FAILURE, 0);

    operationResults.addResult(result1);
    assertTrue(operationResults.wasSuccessful());
    operationResults.addResult(result2);
    assertTrue(operationResults.wasSuccessful());
    operationResults.addResult(result3);
    assertFalse(operationResults.wasSuccessful());
}
 
开发者ID:inovait,项目名称:neatle,代码行数:13,代码来源:OperationResultsTest.java

示例13: onServicesDiscovered

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status)
{
    if(status == BluetoothGatt.GATT_SUCCESS)
    {

    }
    Log.d(TAG, "Service discovered with status " + status);
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:9,代码来源:BLEMiBand2Helper.java

示例14: testStringValues

@Test
public void testStringValues() {
    String dataStr = "lorem ipsum dolor sit amet";
    CommandResult commandResult = new CommandResult(Neatle.createUUID(1), dataStr.getBytes(Charset.forName("UTF8")), BluetoothGatt.GATT_SUCCESS, 1);
    assertEquals(dataStr, commandResult.getValueAsString());

    CommandResult commandResult2 = new CommandResult(Neatle.createUUID(1), null, BluetoothGatt.GATT_SUCCESS, 1);
    assertNull(commandResult2.getValueAsString());

    CommandResult commandResult3 = new CommandResult(Neatle.createUUID(1), new byte[]{}, BluetoothGatt.GATT_SUCCESS, 1);
    assertEquals("", commandResult3.getValueAsString());
}
 
开发者ID:inovait,项目名称:neatle,代码行数:12,代码来源:CommandResultTest.java

示例15: onCharacteristicRead

@Override
public final void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
	if (status == BluetoothGatt.GATT_SUCCESS) {
		Logger.i(mLogSession, "Read Response received from " + characteristic.getUuid() + ", value: " + ParserUtils.parse(characteristic));

		if (isBatteryLevelCharacteristic(characteristic)) {
			final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
			Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
			mCallbacks.onBatteryValueReceived(batteryValue);

			// The Battery Level value has been read. Let's try to enable Battery Level notifications.
			// If the Battery Level characteristic does not have the NOTIFY property, proceed with the initialization queue.
			if (!setBatteryNotifications(true))
				nextRequest();
		} else {
			// The value has been read. Notify the manager and proceed with the initialization queue.
			onCharacteristicRead(gatt, characteristic);
			nextRequest();
		}
	} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
		if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
			DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
			mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
		}
	} else {
		DebugLogger.e(TAG, "onCharacteristicRead error " + status);
		onError(ERROR_READ_CHARACTERISTIC, status);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:29,代码来源:BleManager.java


注:本文中的android.bluetooth.BluetoothGatt.GATT_SUCCESS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。