List of usage examples for android.bluetooth BluetoothGattService getUuid
public UUID getUuid()
From source file:Main.java
public static String serviceId(BluetoothGattService service) { return service.getUuid().toString(); }
From source file:Main.java
public static BluetoothGattService findService(UUID uuid, List<BluetoothGattService> gattServices) { if (gattServices == null) return null; for (BluetoothGattService gattService : gattServices) { if (uuid.equals(gattService.getUuid())) { return gattService; }/*from w ww. j av a 2 s . c o m*/ } return null; }
From source file:com.kraker.myocmd.TestService1.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;//from www . ja v a 2 s.c om String uuid = null; String unknownServiceString = getResources().getString(R.string.unknown_service); ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); // 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); characteristicTX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX); characteristicRX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX); } }
From source file:edu.stanford.cs.sing.helena.DeviceControlActivity.java
private void checkServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/*from w ww.jav a 2 s. c o m*/ String uuid; // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { uuid = gattService.getUuid().toString(); //only interested in helena service if (uuid.equals(HelenaGattAttributes.HELENA_SERVICE)) { mHelenaService = gattService; List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { //only interested in this characteristic if (gattCharacteristic.getUuid().toString().equals(HelenaGattAttributes.UUID_LISTED_DEVICE)) { mNotifyCharacteristic = gattCharacteristic; final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { //Initiate notifications mNotifyCharacteristic = gattCharacteristic; mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, true); } } } } else { Log.d(TAG, "Skipping other services"); } } }
From source file:com.cypress.cysmart.ListAdapters.CarouselPagerAdapter.java
@Override public Fragment getItem(int position) { // Make the first pager bigger than others if (position == ProfileControlFragment.FIRST_PAGE) { scale = ProfileControlFragment.BIG_SCALE; } else {//www . j a v a 2s.c o m scale = ProfileControlFragment.SMALL_SCALE; } position = position % ProfileControlFragment.PAGES; HashMap<String, BluetoothGattService> item = currentServiceData.get(position); BluetoothGattService bgs = item.get("UUID"); /** * Looking for the image corresponding to the UUID.if no suitable image * resource is found assign the default unknown resource */ int imageId = GattAttributes.lookupImage(bgs.getUuid().toString()); String name = GattAttributes.lookup(bgs.getUuid().toString(), context.getResources().getString(R.string.profile_control_unknown_service)); String uuid = bgs.getUuid().toString(); if (uuid.equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) { name = context.getResources().getString(R.string.findme_fragment); } if (uuid.equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_SERVICE)) { name = context.getResources().getString(R.string.proximity_fragment); } if (uuid.equalsIgnoreCase(GattAttributes.CAPSENSE_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.CAPSENSE_SERVICE_CUSTOM)) { List<BluetoothGattCharacteristic> gattCharacteristics = bgs.getCharacteristics(); if (gattCharacteristics.size() > 1) { imageId = GattAttributes.lookupImageCapSense(bgs.getUuid().toString()); name = GattAttributes.lookupNameCapSense(bgs.getUuid().toString(), context.getResources().getString(R.string.profile_control_unknown_service)); } else { String characteristicUUID = gattCharacteristics.get(0).getUuid().toString(); imageId = GattAttributes.lookupImageCapSense(characteristicUUID); name = GattAttributes.lookupNameCapSense(characteristicUUID, context.getResources().getString(R.string.profile_control_unknown_service)); } } if (uuid.equalsIgnoreCase(GattAttributes.GENERIC_ACCESS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.GENERIC_ATTRIBUTE_SERVICE)) { name = context.getResources().getString(R.string.gatt_db); } if (uuid.equalsIgnoreCase(GattAttributes.BAROMETER_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.ACCELEROMETER_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.ANALOG_TEMPERATURE_SERVICE)) { name = context.getResources().getString(R.string.sen_hub); } if (uuid.equalsIgnoreCase(GattAttributes.HUMAN_INTERFACE_DEVICE_SERVICE)) { String connectedDeviceName = BluetoothLeService.getmBluetoothDeviceName(); String remoteName = context.getString(R.string.rdk_emulator_view); if (connectedDeviceName.indexOf(remoteName) != -1) { name = context.getResources().getString(R.string.rdk_emulator_view); imageId = R.drawable.emulator; } } Fragment curFragment = CarouselFragment.newInstance(imageId, scale, name, uuid, bgs); return curFragment; }
From source file:com.beestar.ble.ble.ui.BleScanActivity.java
private void setBleServiceListener() { mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { @Override//w ww . ja va 2 s. c o m public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServiceList = gatt.getServices(); serviceList.clear(); for (BluetoothGattService service : gattServiceList) { String serviceUuid = service.getUuid().toString(); serviceList.add(MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); Log.i(TAG, MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); String[] charArra = new String[characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { String charUuid = characteristics.get(i).getUuid().toString(); charArra[i] = MyGattAttributes.lookup(charUuid, "Unknown") + "\n" + charUuid; } characteristicList.add(charArra); } mHandler.sendEmptyMessage(SERVICE_SHOW); } } }); // //Ble?? // mBleService.setOnLeScanListener(new BleService.OnLeScanListener() { // @Override // public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // //???Ble????? // } // }); // //Ble // mBleService.setOnConnectListener(new BleService.OnConnectListener() { // @Override // public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { // if (newState == BluetoothProfile.STATE_DISCONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTING) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { // //Ble // } // } // }); // //Ble?? // mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { // @Override // public void onServicesDiscovered(BluetoothGatt gatt, int status) { // // } // }); // //Ble? // mBleService.setOnDataAvailableListener(new BleService.OnDataAvailableListener() { // @Override // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // //??? // } // // @Override // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // //?? // } // @Override // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { // // } // }); mBleService.setOnReadRemoteRssiListener(new BleService.OnReadRemoteRssiListener() { @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { Log.i(TAG, "onReadRemoteRssi: rssi = " + rssi); } }); }
From source file:com.junkchen.blelib.sample.BleScanActivity.java
private void setBleServiceListener() { mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { @Override/*ww w . j a v a2s .c om*/ public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServiceList = gatt.getServices(); characteristicList = new ArrayList<>(); serviceList.clear(); for (BluetoothGattService service : gattServiceList) { String serviceUuid = service.getUuid().toString(); serviceList.add(MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); Log.i(TAG, MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); String[] charArra = new String[characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { String charUuid = characteristics.get(i).getUuid().toString(); charArra[i] = MyGattAttributes.lookup(charUuid, "Unknown") + "\n" + charUuid; } characteristicList.add(charArra); } mHandler.sendEmptyMessage(SERVICE_SHOW); } } }); // //Ble?? // mBleService.setOnLeScanListener(new BleService.OnLeScanListener() { // @Override // public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // //???Ble????? // } // }); // //Ble // mBleService.setOnConnectListener(new BleService.OnConnectListener() { // @Override // public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { // if (newState == BluetoothProfile.STATE_DISCONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTING) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { // //Ble // } // } // }); // //Ble?? // mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { // @Override // public void onServicesDiscovered(BluetoothGatt gatt, int status) { // // } // }); // //Ble? // mBleService.setOnDataAvailableListener(new BleService.OnDataAvailableListener() { // @Override // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // //??? // } // // @Override // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // //?? // } // @Override // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { // // } // }); mBleService.setOnReadRemoteRssiListener(new BleService.OnReadRemoteRssiListener() { @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { Log.i(TAG, "onReadRemoteRssi: rssi = " + rssi); } }); }
From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java
private synchronized void stopAdvertising(BluetoothGattService service) { mGattServer.removeService(service);//ww w. ja va 2 s . co m mClassicAdvertiser.removeService(service.getUuid()); if (mLeAdvertiser != null) { AdvertiseCallback callback = mLeAdvertiseCallbacks.remove(service.getUuid()); mLeAdvertiser.stopAdvertising(callback); } }
From source file:com.example.bluetoothlegatt.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;//from w ww . 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.touchKin.touchkinapp.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/*from www.j a va 2 s .c om*/ 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. characteristicTX = gattService .getCharacteristic(UUID.fromString("00001525-1212-efde-1523-785feabcd123")); characteristicRX = gattService .getCharacteristic(UUID.fromString("00001525-1212-efde-1523-785feabcd123")); 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); }