List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid
public UUID getUuid()
From source file:org.zpcat.ble.ui.central.DeviceControlActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void displayGattServices(List<BluetoothGattService> gattServices) { Log.d("displayGATTServices"); if (gattServices == null) return;//w w w. j a va 2 s .c o m 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(); currentServiceData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString)); currentServiceData.put(LIST_UUID, uuid); gattServiceData.add(currentServiceData); 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(); currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString)); currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } mGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(this, gattServiceData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }, gattCharacteristicData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }); mGattServicesList.setAdapter(gattServiceAdapter); }
From source file:com.megster.cordova.ble.central.Peripheral.java
private String generateHashKey(UUID serviceUUID, BluetoothGattCharacteristic characteristic) { return String.valueOf(serviceUUID) + "|" + characteristic.getUuid() + "|" + characteristic.getInstanceId(); }
From source file:com.cypress.cysmart.BLEServiceFragments.FindMeService.java
/** * Method to get required characteristics from service *///from w w w .j av a 2 s . co m private void getGattData() { LinearLayout ll_layout = (LinearLayout) rootView.findViewById(R.id.linkloss_layout); LinearLayout im_layout = (LinearLayout) rootView.findViewById(R.id.immalert_layout); LinearLayout tp_layout = (LinearLayout) rootView.findViewById(R.id.transmission_layout); RelativeLayout tpr_layout = (RelativeLayout) rootView.findViewById(R.id.transmission_rel_layout); for (int position = 0; position < mExtraservice.size(); position++) { HashMap<String, BluetoothGattService> item = mExtraservice.get(position); BluetoothGattService bgs = item.get("UUID"); List<BluetoothGattCharacteristic> gattCharacteristicsCurrent = bgs.getCharacteristics(); for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristicsCurrent) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.ALERT_LEVEL)) { if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE)) { ll_layout.setVisibility(View.VISIBLE); mSpinnerLinkLoss = (CustomSpinner) rootView.findViewById(R.id.linkloss_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_linkloss = ArrayAdapter.createFromResource(getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_linkloss.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerLinkLoss.setAdapter(adapter_linkloss); mSpinnerLinkLoss.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) { im_layout.setVisibility(View.VISIBLE); mSpinnerImmediateAlert = (CustomSpinner) rootView.findViewById(R.id.immediate_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_immediate_alert = ArrayAdapter.createFromResource( getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_immediate_alert .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerImmediateAlert.setAdapter(adapter_immediate_alert); mSpinnerImmediateAlert.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } } if (uuidchara.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_LEVEL)) { tp_layout.setVisibility(View.VISIBLE); tpr_layout.setVisibility(View.VISIBLE); mReadCharacteristic_tp = gattCharacteristic; mTransmissionPower = (ImageView) rootView.findViewById(R.id.findme_tx_power_img); mTransmissionPowerValue = (TextView) rootView.findViewById(R.id.findme_tx_power_txt); if (mReadCharacteristic_tp != null) { prepareBroadcastDataReadtp(mReadCharacteristic_tp); } } } } }
From source file:com.mikroe.hexiwear_android.DeviceScanActivity.java
private void displayGattServices(List<List<BluetoothGattService>> devicesGattServices) { if (devicesGattServices == null) return;//from ww w . j a v a2s . c om String uuid = null; ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>(); ArrayList<ArrayList<BluetoothGattCharacteristic>> tempGattCharacteristics = new ArrayList<>(); mGattsCharacteristics.clear(); for (List<BluetoothGattService> gattServices : devicesGattServices) { // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, String> currentServiceData = new HashMap<String, String>(); uuid = gattService.getUuid().toString(); currentServiceData.put(LIST_UUID, uuid); gattServiceData.add(currentServiceData); 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(); if (uuid.equals(UUID_CHAR_ALERTIN)) { alertInCharacteristic = gattCharacteristic; byte[] value = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; alertInCharacteristic.setValue(value); } currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } tempGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } mGattsCharacteristics.add(tempGattCharacteristics); } mHandler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(DeviceScanActivity.this, MainScreenActivity.class); startActivity(intent); } }, 1500); }
From source file:de.blinkt.openvpn.bluetooth.service.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (TX_CHAR_UUID1.equals(characteristic.getUuid())) { byte[] txValue = characteristic.getValue(); int lengthData = (txValue[1] & 0x7f) + 1; int dataStatue = txValue[1] & 0x80; String messageFromBlueTooth = HexStringExchangeBytesUtil.bytesToHexString(characteristic.getValue()); Log.e("UartService", messageFromBlueTooth); if (lengthData == 1 && dataStatue == 0x80) { //TODO ?? // messages.add(messageFromBlueTooth); ArrayList<String> onePackagemessage = new ArrayList<>(); onePackagemessage.add(messageFromBlueTooth); intent.putStringArrayListExtra(EXTRA_DATA, onePackagemessage); LocalBroadcastManager.getInstance(ICSOpenVPNApplication.getContext()).sendBroadcast(intent); return; } else {/*from www . j a v a2s . c o m*/ //TODO ? if (TextUtils.isEmpty(messageFromBlueTooth)) { return; } if (messages == null) { messages = new ArrayList<>(); } messages.add(messageFromBlueTooth); if (messages.size() < lengthData) { if (dataStatue == 0x80) { isWholeDataPackage = true; } return; } if (isWholeDataPackage || dataStatue == 0x80) { isWholeDataPackage = false; sortMessage(); intent.putStringArrayListExtra(EXTRA_DATA, messages); Log.e("UartService", messages.toString()); LocalBroadcastManager.getInstance(ICSOpenVPNApplication.getContext()).sendBroadcast(intent); } } // intent.putExtra(EXTRA_DATA, messageFromBlueTooth); // if(messages.size()==0){ // return; // } } }
From source file:com.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findReadableCharacteristic(BluetoothGattService service, UUID characteristicUUID) { BluetoothGattCharacteristic characteristic = null; int read = BluetoothGattCharacteristic.PROPERTY_READ; List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & read) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c;//from w ww . j av a2 s.c om break; } } // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties if (characteristic == null) { characteristic = service.getCharacteristic(characteristicUUID); } return characteristic; }
From source file:com.ble.BLService.java
public void writeCharacteristic(BluetoothGattCharacteristic characteristic, String value) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized Characteristic"); return;// ww w . j a v a2 s . c o m } if (UUID_STM32_WRITE_TO_DEVICE.equals(characteristic.getUuid())) { add = value; byte[] dataByte = value.getBytes(); characteristic.setValue(dataByte); characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); mBluetoothGatt.writeCharacteristic(characteristic); } }
From source file:com.wearme.fat.ui.MainActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/* ww w. j a v a2 s. c om*/ for (BluetoothGattService gattService : gattServices) { //f433bd80 //06aba6de if (gattService.getUuid().toString().startsWith("f433bd80")) { List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { if (gattCharacteristic.getUuid().toString().startsWith("29f11080")) { GattAttributes.mobileToEquipmentCharacteristic = gattCharacteristic; } else if (gattCharacteristic.getUuid().toString().startsWith("1a2ea400")) { mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); } } } if (gattService.getUuid().toString().startsWith("06aba6de")) { List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { if (gattCharacteristic.getUuid().toString().startsWith("29f11080")) { GattAttributes.mobileToEquipmentCharacteristic = gattCharacteristic; } else if (gattCharacteristic.getUuid().toString().startsWith("1a2ea400")) { mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); } } } } }
From source file:com.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findWritableCharacteristic(BluetoothGattService service, UUID characteristicUUID, int writeType) { BluetoothGattCharacteristic characteristic = null; // get write property int writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE; if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) { writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE; }/*from w w w . j a va2s . c o m*/ List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & writeProperty) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c; break; } } // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties if (characteristic == null) { characteristic = service.getCharacteristic(characteristicUUID); } return characteristic; }
From source file:com.muggins.test.ble.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/*from w ww . j av a 2s .c o m*/ 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>(); if (SampleGattAttributes.SERVICE_NUMBER.equals(gattService.getUuid().toString())) { uuid = gattService.getUuid().toString(); // currentServiceData.put(LIST_NAME, "?"); // currentServiceData.put(LIST_UUID, "??1234"); // gattServiceData.add(currentServiceData); 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>(); if (SampleGattAttributes.HEART_RATE_MEASUREMENT .equals(gattCharacteristic.getUuid().toString())) { uuid = gattCharacteristic.getUuid().toString(); currentCharaData.put(LIST_NAME, "?"); currentCharaData.put(LIST_UUID, ""); gattCharacteristicGroupData.add(currentCharaData); final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { // If there is an active notification on a characteristic, clear // it first so it doesn't update the data field on the user interface. Log.e("BluetoothLeService", "read"); if (mNotifyCharacteristic != null) { mBluetoothLeService.setCharacteristicNotification( // mNotifyCharacteristic, false); mNotifyCharacteristic, true); mNotifyCharacteristic = null; } mBluetoothLeService.readCharacteristic(gattCharacteristic); // Intent intent = new Intent(DeviceControlActivity.this, ShowWave.class); // startActivity(intent); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { Log.e("BluetoothLeService", "notify"); mNotifyCharacteristic = gattCharacteristic; mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); } } } mGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } } SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(this, gattServiceData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }, gattCharacteristicData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }); mGattServicesList.setAdapter(gattServiceAdapter); }