本文整理匯總了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;
}
}
示例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);
}
示例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));
}
示例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));
}
}
}
示例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);
}
}
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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));
}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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");
}
}
}