本文整理匯總了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;
}
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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");
}
示例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);
}
}
示例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");
}
}
}
示例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();
}
}
示例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");
}
}
}
示例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);
}
}
示例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 + ")";
}
}
示例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());
}
示例13: onServicesDiscovered
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status)
{
if(status == BluetoothGatt.GATT_SUCCESS)
{
}
Log.d(TAG, "Service discovered with status " + status);
}
示例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());
}
示例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);
}
}