當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattCharacteristic.getUuid方法代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.getUuid方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.getUuid方法的具體用法?Java BluetoothGattCharacteristic.getUuid怎麽用?Java BluetoothGattCharacteristic.getUuid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.BluetoothGattCharacteristic的用法示例。


在下文中一共展示了BluetoothGattCharacteristic.getUuid方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCharacteristicReadRequest

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
 * Read requests can be performed in several steps, with increasing offsets (e.g. when the MTU
 * is very small). We need to handle this manually.
 *
 * We only support reading from the apduCharacteristic; if any other characteristic is read,
 * we return an error.
 */
@Override
public synchronized void onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset,
                                        BluetoothGattCharacteristic characteristic) {

    Log.d(TAG, "Device tried to read characteristic: " + characteristic.getUuid());

    if (characteristic.getUuid() != apduCharacteristic.getUuid()) {
        Log.d(TAG, "Not the APDU characteristic, returning error.");
        gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_READ_NOT_PERMITTED, offset, null);
        return;
    }

    while (! dataWaiting) {
        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    byte[] value = apduCharacteristic.getValue();

    if (offset > value.length) {
        Log.d(TAG, "Offset " + String.valueOf(offset) + " is larger than length " + String.valueOf(value.length));
        gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_INVALID_OFFSET, offset, null);
    } else {
        byte[] part = Arrays.copyOfRange(value, offset, value.length);
        Log.d(TAG, "Sending blob starting at offset " + String.valueOf(offset) + ": " + ByteUtils.bytesToHex(part));

        gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, part);
    }
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:40,代碼來源:GattService.java

示例2: onNotification

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID alertUUID = characteristic.getUuid();
    if (alertUUID.equals(Consts.UUID_NOTIFICATION_HEARTRATE)) {
        final byte hearbeat =
                characteristic.getValue()[1];

        handler.post(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(MainActivity.this,
                        "Heartbeat: " + Byte.toString(hearbeat)
                        , Toast.LENGTH_SHORT).show();

                // Set max volume and read heart beat.
                setMaxVolume();
                HearBeatVoice.readHeartbeat(mySounds, hearbeat);
                mySounds.playAllAsync();
            }
        });
    }
    else if (alertUUID.equals(Consts.UUID_BUTTON_TOUCH)) {
        handler.post(new Runnable() {

            @Override
            public void run() {
                getNewHeartBeat();
                Toast.makeText(MainActivity.this,
                        "Button Press! "
                        , Toast.LENGTH_SHORT).show();
            }
        });
    }
}
 
開發者ID:yonixw,項目名稱:mi-band-2,代碼行數:36,代碼來源:MainActivity.java

示例3: checkServices

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void checkServices(List<BluetoothGattService> gattServices) {
        if (gattServices == null) return;
        String uuid = null;
        String unknownServiceString = getResources().getString(R.string.unknown_service);
        String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
        ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
        ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData
                = new ArrayList<ArrayList<HashMap<String, String>>>();
        mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

        // Loops through available GATT Services.
        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData = new HashMap<String, String>();
            //           uuid = gattService.getUuid().toString();
            UUID serviceUuid = gattService.getUuid();
            if (hackmelockDevice.HACKMELOCK_SERVICE_UUID.equals(serviceUuid)) {
                Log.d("GattServices", "Found Hackmelock service!");
                hackmelockService = gattService;
                hackmelockCommandChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_COMMAND_UUID);
                hackmelockStatusChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_STATUS_UUID);
                hackmelockDataTransferChar = hackmelockService.getCharacteristic(hackmelockDevice.HACKMELOCK_DATATRANSFER_UUID);

                ArrayList<HashMap<String, String>> gattCharacteristicGroupData =
                        new ArrayList<HashMap<String, String>>();
                List<BluetoothGattCharacteristic> gattCharacteristics =
                        gattService.getCharacteristics();
                ArrayList<BluetoothGattCharacteristic> charas =
                        new ArrayList<BluetoothGattCharacteristic>();

                // Loops through available Characteristics.
                for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                    charas.add(gattCharacteristic);
                    HashMap<String, String> currentCharaData = new HashMap<String, String>();
//                    uuid = gattCharacteristic.getUuid().toString();
                    UUID characteristicUuid = gattCharacteristic.getUuid();
                    if (hackmelockDevice.HACKMELOCK_STATUS_UUID.equals(characteristicUuid)) {
                        Log.d("GattServices", "Found Hackmelock status characteristic");
                        //if device already paired, read status = auth challenge
                        if (hackmelockDevice.status == HackmelockDevice.Status.PAIRED) {
//                            hackmelockDevice.status = HackmelockDevice.Status.AUTHENTICATING;
                            authenticate();
                        } else {
                            Log.d("GattServices","Status: " + hackmelockDevice.status.toString());
                            // else - if device not yet paired, read status = init pairing
                            mBluetoothLeService.readCharacteristic(gattCharacteristic);
                        }
                    }
                }
                mGattCharacteristics.add(charas);
                gattCharacteristicData.add(gattCharacteristicGroupData);

            }
        }
    }
 
開發者ID:smartlockpicking,項目名稱:hackmelock-android,代碼行數:55,代碼來源:DeviceControlActivity.java

示例4: generateHashKey

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private String generateHashKey(UUID serviceUUID, BluetoothGattCharacteristic characteristic) {
	return String.valueOf(serviceUUID) + "|" + characteristic.getUuid() + "|" + characteristic.getInstanceId();
}
 
開發者ID:lenglengiOS,項目名稱:react-native-blue-manager,代碼行數:4,代碼來源:Peripheral.java

示例5: createCharacteristicRead

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@RestrictTo(RestrictTo.Scope.LIBRARY)
public static CommandResult createCharacteristicRead(BluetoothGattCharacteristic characteristic, int status) {
    long when = System.currentTimeMillis();
    return new CommandResult(characteristic.getUuid(), characteristic.getValue(), status, when);
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:6,代碼來源:CommandResult.java

示例6: createCharacteristicChanged

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@RestrictTo(RestrictTo.Scope.LIBRARY)
public static CommandResult createCharacteristicChanged(BluetoothGattCharacteristic characteristic) {
    long when = System.currentTimeMillis();
    return new CommandResult(characteristic.getUuid(), characteristic.getValue(), BluetoothGatt.GATT_SUCCESS, when);
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:6,代碼來源:CommandResult.java


注:本文中的android.bluetooth.BluetoothGattCharacteristic.getUuid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。