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


Java BluetoothGatt.readCharacteristic方法代码示例

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


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

示例1: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@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,代码行数:21,代码来源:MiFloraSensorEntity.java

示例2: readCharacteristic

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public final boolean readCharacteristic(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) == 0)
		return false;

	return gatt.readCharacteristic(characteristic);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:14,代码来源:BleManager.java

示例3: start

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
protected void start(Connection connection, BluetoothGatt gatt) {
    BluetoothGattService service = gatt.getService(serviceUUID);
    if (service != null) {
        BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUUID);
        if (characteristic != null) {
            NeatleLogger.d("Reading characteristics " + characteristicUUID);
            if (gatt.readCharacteristic(characteristic)) {
                return;
            }
            NeatleLogger.d("Read failed" + characteristicUUID);
        } else {
            NeatleLogger.e("Could not find characteristics " + characteristicUUID);
        }
    } else {
        NeatleLogger.e("Could not find service " + serviceUUID);
    }

    finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
}
 
开发者ID:inovait,项目名称:neatle,代码行数:21,代码来源:ReadCommand.java

示例4: onCharacteristicWrite

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        if(characteristic.getUuid().equals(UUID_TITAG_ENABLE_AIR_TEMP_HUMIDITY)){
            gatt.readCharacteristic(mGattnTitagTempHumidityService.getCharacteristic(UUID_TITAG_GET_AIR_TEMP_HUMIDITY));
        }

        if(characteristic.getUuid().equals(UUID_TITAG_ENABLE_LIGHT)){
            gatt.readCharacteristic(mGattnTitagLightService.getCharacteristic(UUID_TITAG_GET_LIGHT));
        }
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:13,代码来源:TitagSensorEntity.java

示例5: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  for (BluetoothGattService service : gatt.getServices()) {
    if (IMMEDIATE_ALERT_SERVICE.equals(service.getUuid())) {
      BlePair pair = bluetoothGatt.get(gatt.getDevice().getAddress());
      if (pair != null) {
        pair.alertCharacteristic = getCharacteristic(
            gatt,
            IMMEDIATE_ALERT_SERVICE,
            ALERT_LEVEL_CHARACTERISTIC
        );
        gatt.readCharacteristic(pair.alertCharacteristic);
      }
    }

    if (FIND_ME_SERVICE.equals(service.getUuid())) {
      if (!service.getCharacteristics().isEmpty()) {
        buttonCharacteristic = service.getCharacteristics().get(0);
        setCharacteristicNotification(gatt, buttonCharacteristic, true);
      }
    }
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:24,代码来源:BleService.java

示例6: onCharacteristicRead

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic c, int status) {
    String characteristic_uuid = c.getUuid().toString();
    Log.i(TAG, "BluetoothGattCallback.onCharacteristicRead: CharacteristicUuid=" + characteristic_uuid + "status=" + status);
    characteristicReadQueue.remove();


    //XXX until we figure out what's going on
    if (characteristic_uuid.equals(OWDevice.OnewheelCharacteristicBatteryRemaining)) {
        mainActivity.updateBatteryRemaining(c.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1));
    }  else if (characteristic_uuid.equals(OWDevice.OnewheelCharacteristicRidingMode)) {
         Log.d(TAG, "Got ride mode from the main UI thread:" + c.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1));
     }

    mOWDevice.processUUID(c);

    if (BuildConfig.DEBUG) {
        byte[] v_bytes = c.getValue();


        StringBuilder sb = new StringBuilder();
        for (byte b : c.getValue()) {
            sb.append(String.format("%02x", b));
        }

        Log.d(TAG, "HEX %02x: " + sb);
        Log.d(TAG, "Arrays.toString() value: " + Arrays.toString(v_bytes));
        Log.d(TAG, "String value: " + c.getStringValue(0));
        Log.d(TAG, "Unsigned short: " + unsignedShort(v_bytes));
        Log.d(TAG, "getIntValue(FORMAT_UINT8,0) " + c.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
        Log.d(TAG, "getIntValue(FORMAT_UINT8,1) " + c.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1));
    }
    // Callback to make sure the queue is drained
    if (characteristicReadQueue.size() > 0) {
        gatt.readCharacteristic(characteristicReadQueue.element());
    }


}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:40,代码来源:BluetoothUtilImpl.java

示例7: onDescriptorWrite

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    Log.i(TAG, "onDescriptorWrite: " + status);
    descriptorWriteQueue.remove();  //pop the item that we just finishing writing
    //if there is more to write, do it!
    if(descriptorWriteQueue.size() > 0) {
        gatt.writeDescriptor(descriptorWriteQueue.element());
    } else if(characteristicReadQueue.size() > 0) {
        gatt.readCharacteristic(characteristicReadQueue.element());
    }
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:12,代码来源:BluetoothUtilImpl.java

示例8: onDescriptorWrite

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    if (DESCRIPTOR_CONFIG.equals(descriptor.getUuid())) {
        BluetoothGattCharacteristic characteristic = gatt.getService(SERVICE_UUID).getCharacteristic(CHARACTERISTIC_COUNTER_UUID);
        gatt.readCharacteristic(characteristic);
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:8,代码来源:GattClient.java

示例9: readCharacteristic

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Sends the read request to the given characteristic.
 *
 * @param characteristic the characteristic to read
 * @return true if request has been sent
 */
protected final boolean readCharacteristic(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = mBluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) == 0)
		return false;

	Logger.v(mLogSession, "Reading characteristic " + characteristic.getUuid());
	Logger.d(mLogSession, "gatt.readCharacteristic(" + characteristic.getUuid() + ")");
	return gatt.readCharacteristic(characteristic);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:21,代码来源:BleManager.java

示例10: readNext

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
private void readNext(BluetoothGatt gatt) {
    BluetoothGattCharacteristic characteristic = queue.poll();
    if (characteristic == null) {
        finish(CommandResult.createEmptySuccess(null));
        return;
    }
    if (!gatt.readCharacteristic(characteristic)) {
        finish(CommandResult.createErrorResult(null, BluetoothGatt.GATT_FAILURE));
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:11,代码来源:ReadAllCommand.java

示例11: readCharacteristicNoFailure

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
private String readCharacteristicNoFailure(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
    if (mConnectionState != STATE_CONNECTED_AND_READY)
        return "not_ready";
    if (characteristic == null)
        return "unknown";
    logi("readCharacteristicNoFailure");
    gatt.readCharacteristic(characteristic);
    try {
        synchronized (mLock) {
            while ((!mRequestCompleted && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
                mLock.wait();
        }
    } catch (final InterruptedException e) {
        loge("Sleeping interrupted", e);
    }

    if (mAborted)
        return "unknown";

    if (mError != 0)
        return "unknown";

    if (mConnectionState != STATE_CONNECTED_AND_READY)
        return "unknown";
    return characteristic.getStringValue(0);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:27,代码来源:DfuBaseService.java

示例12: readVersion

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Reads the DFU Version characteristic if such exists. Otherwise it returns 0.
 *
 * @param gatt           the GATT device
 * @param characteristic the characteristic to read
 * @return a version number or 0 if not present on the bootloader
 * @throws DeviceDisconnectedException
 * @throws DfuException
 * @throws UploadAbortedException
 */
private int readVersion(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to read version number", mConnectionState);
    // If the DFU Version characteristic is not available we return 0.
    if (characteristic == null)
        return 0;

    mReceivedData = null;
    mError = 0;

    logi("Reading DFU version number...");
    sendLogBroadcast(LOG_LEVEL_VERBOSE, "Reading DFU version number...");

    gatt.readCharacteristic(characteristic);

    // We have to wait until device receives a response or an error occur
    try {
        synchronized (mLock) {
            while ((!mRequestCompleted && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
                mLock.wait();
        }
    } catch (final InterruptedException e) {
        loge("Sleeping interrupted", e);
    }

    if (mAborted)
        throw new UploadAbortedException();

    if (mError != 0)
        throw new DfuException("Unable to read version number", mError);

    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to read version number", mConnectionState);

    // The version is a 16-bit unsigned int
    return characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:48,代码来源:DfuBaseService.java

示例13: onServicesDiscovered

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        mGattnTitagBatteryService = gatt.getService(UUID_TITAG_BATTERY_SERVICE);
        mGattnTitagTempHumidityService = gatt.getService(UUID_TITAG_AIR_TEMP_HUMIDITY_SERVICE);
        mGattnTitagLightService = gatt.getService(UUID_TITAG_LIGHT_SERVICE);
        if(mGattnTitagBatteryService != null){
            gatt.readCharacteristic(mGattnTitagBatteryService.getCharacteristic(UUID_TITAG_GET_BATTERY));
        }
    }
    else{
        gatt.close();
        mIsConnecting = false;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:16,代码来源:TitagSensorEntity.java

示例14: onCharacteristicWrite

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    if(status == BluetoothGatt.GATT_SUCCESS){
        boolean rs = gatt.readCharacteristic(mGattMiFloraService.getCharacteristic(UUID_MI_FLORA_GET_DATA));
        if(!rs){
            Log.i(mTAG, "Can't read mGattMiFloraGetDataCharacteristic");
        }
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:10,代码来源:MiFloraSensorEntity.java


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