Java Code Examples for android.bluetooth.BluetoothGattService#SERVICE_TYPE_PRIMARY
The following examples show how to use
android.bluetooth.BluetoothGattService#SERVICE_TYPE_PRIMARY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeProfile.java From sample-bluetooth-le-gattserver with Apache License 2.0 | 6 votes |
/** * Return a configured {@link BluetoothGattService} instance for the * Current Time Service. */ public static BluetoothGattService createTimeService() { BluetoothGattService service = new BluetoothGattService(TIME_SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY); // Current Time characteristic BluetoothGattCharacteristic currentTime = new BluetoothGattCharacteristic(CURRENT_TIME, //Read-only characteristic, supports notifications BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_READ); BluetoothGattDescriptor configDescriptor = new BluetoothGattDescriptor(CLIENT_CONFIG, //Read/write descriptor BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE); currentTime.addDescriptor(configDescriptor); // Local Time Information characteristic BluetoothGattCharacteristic localTime = new BluetoothGattCharacteristic(LOCAL_TIME_INFO, //Read-only characteristic BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ); service.addCharacteristic(currentTime); service.addCharacteristic(localTime); return service; }
Example 2
Source File: GattServer.java From blefun-androidthings with Apache License 2.0 | 6 votes |
private BluetoothGattService createAwesomenessService() { BluetoothGattService service = new BluetoothGattService(SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY); // Counter characteristic (read-only, supports notifications) BluetoothGattCharacteristic counter = new BluetoothGattCharacteristic(CHARACTERISTIC_COUNTER_UUID, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_READ); BluetoothGattDescriptor counterConfig = new BluetoothGattDescriptor(DESCRIPTOR_CONFIG, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE); counter.addDescriptor(counterConfig); BluetoothGattDescriptor counterDescription = new BluetoothGattDescriptor(DESCRIPTOR_USER_DESC, BluetoothGattDescriptor.PERMISSION_READ); counter.addDescriptor(counterDescription); // Interactor characteristic BluetoothGattCharacteristic interactor = new BluetoothGattCharacteristic(CHARACTERISTIC_INTERACTOR_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, BluetoothGattCharacteristic.PERMISSION_WRITE); BluetoothGattDescriptor interactorDescription = new BluetoothGattDescriptor(DESCRIPTOR_USER_DESC, BluetoothGattDescriptor.PERMISSION_READ); interactor.addDescriptor(interactorDescription); service.addCharacteristic(counter); service.addCharacteristic(interactor); return service; }
Example 3
Source File: BLEServicePeripheral.java From unity-bluetooth with MIT License | 6 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void start(String uuidString) { mServiceUUID = UUID.fromString(uuidString); if (mBtAdvertiser == null) { return; } BluetoothGattService btGattService = new BluetoothGattService(mServiceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY); btGattService.addCharacteristic(mBtGattCharacteristic); BluetoothGattServerCallback btGattServerCallback = createGattServerCallback(mServiceUUID, UUID.fromString(CHARACTERISTIC_UUID)); mBtGattServer = mBtManager.openGattServer(mActivity.getApplicationContext(), btGattServerCallback); mBtGattServer.addService(btGattService); mDataBuilder = new AdvertiseData.Builder(); mDataBuilder.setIncludeTxPowerLevel(false); mDataBuilder.addServiceUuid(new ParcelUuid(mServiceUUID)); mSettingsBuilder=new AdvertiseSettings.Builder(); mSettingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED); mSettingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH); mBleAdvertiser = mBtAdapter.getBluetoothLeAdvertiser(); mBleAdvertiser.startAdvertising(mSettingsBuilder.build(), mDataBuilder.build(), mAdvertiseCallback); }
Example 4
Source File: BatteryServiceFragment.java From ble-test-peripheral-android with Apache License 2.0 | 6 votes |
public BatteryServiceFragment() { mBatteryLevelCharacteristic = new BluetoothGattCharacteristic(BATTERY_LEVEL_UUID, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_READ); mBatteryLevelCharacteristic.addDescriptor( Peripheral.getClientCharacteristicConfigurationDescriptor()); mBatteryLevelCharacteristic.addDescriptor( Peripheral.getCharacteristicUserDescriptionDescriptor(BATTERY_LEVEL_DESCRIPTION)); mBatteryService = new BluetoothGattService(BATTERY_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY); mBatteryService.addCharacteristic(mBatteryLevelCharacteristic); }
Example 5
Source File: AbstractHOGPServer.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Setup Battery Service * * @return the service */ private BluetoothGattService setUpBatteryService() { final BluetoothGattService service = new BluetoothGattService(SERVICE_BATTERY, BluetoothGattService.SERVICE_TYPE_PRIMARY); // Battery Level final BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic( CHARACTERISTIC_BATTERY_LEVEL, BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED); final BluetoothGattDescriptor clientCharacteristicConfigurationDescriptor = new BluetoothGattDescriptor( DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE); clientCharacteristicConfigurationDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); characteristic.addDescriptor(clientCharacteristicConfigurationDescriptor); service.addCharacteristic(characteristic); return service; }
Example 6
Source File: ServicesListAdapter.java From BLEService with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { // get already available view or create new if necessary FieldReferences fields; if (convertView == null) { convertView = mInflater.inflate(R.layout.peripheral_list_services_item, null); fields = new FieldReferences(); fields.serviceName = (TextView)convertView.findViewById(R.id.peripheral_list_services_name); fields.serviceUuid = (TextView)convertView.findViewById(R.id.peripheral_list_services_uuid); fields.serviceType = (TextView)convertView.findViewById(R.id.peripheral_list_service_type); convertView.setTag(fields); } else { fields = (FieldReferences) convertView.getTag(); } // set proper values into the view BluetoothGattService service = mBTServices.get(position); String uuid = service.getUuid().toString().toLowerCase(Locale.getDefault()); String name = BleNamesResolver.resolveServiceName(uuid); String type = (service.getType() == BluetoothGattService.SERVICE_TYPE_PRIMARY) ? "Primary" : "Secondary"; fields.serviceName.setText(name); fields.serviceUuid.setText(uuid); fields.serviceType.setText(type); return convertView; }
Example 7
Source File: LoggerUtilBluetoothServices.java From RxAndroidBle with Apache License 2.0 | 5 votes |
private static String createServiceType(BluetoothGattService bluetoothGattService) { if (bluetoothGattService.getType() == BluetoothGattService.SERVICE_TYPE_PRIMARY) { return "Primary Service"; } else { return "Secondary Service"; } }
Example 8
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void connectNodeWithDebug(){ BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); BluetoothDeviceShadow shadowDevice = Shadow.extract(device); BluetoothGattService debugService = new BluetoothGattService(BLENodeDefines.Services .Debug.DEBUG_SERVICE_UUID,BluetoothGattService.SERVICE_TYPE_PRIMARY); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY)); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY) ); shadowDevice.addService(debugService); Node node = createNode(device); Assert.assertEquals(Node.State.Idle, node.getState()); node.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false), any(BluetoothGattCallback.class)); Assert.assertEquals(Node.State.Connected, node.getState()); Assert.assertTrue(node.getDebug()!=null); }
Example 9
Source File: UartPeripheralService.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
public UartPeripheralService(Context context) { super(context); mName = LocalizationManager.getInstance().getString(context, "peripheral_uart_title"); mRxCharacteristic.addDescriptor(mRxConfigDescriptor); // TODO: add TX characteristic extended properties descriptor mService = new BluetoothGattService(kUartServiceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY); mService.addCharacteristic(mTxCharacteristic); mService.addCharacteristic(mRxCharacteristic); }
Example 10
Source File: GattServerTests.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@Test public void addGattServiceToServerTest() { // Context of the app under test. BluetoothGattService service = new BluetoothGattService(UUID.randomUUID(), BluetoothGattService.SERVICE_TYPE_PRIMARY); AddGattServerServiceMockTransaction addServiceTransaction = new AddGattServerServiceMockTransaction(FitbitGatt.getInstance().getServer(), GattState.ADD_SERVICE_SUCCESS, service, false); GattServerConnection serverConn = FitbitGatt.getInstance().getServer(); serverConn.runTx(addServiceTransaction, result -> Assert.assertEquals(result.resultStatus, TransactionResult.TransactionResultStatus.SUCCESS)); }
Example 11
Source File: BleService.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
private BleService(final UUID uuid, final BleCharacteristic[] characteristics, final boolean constructorOverloadEnabler2000) { final int serviceType = BluetoothGattService.SERVICE_TYPE_PRIMARY; m_native = new BluetoothGattService(uuid, serviceType); for( int i = 0; i < characteristics.length; i++ ) { m_native.addCharacteristic(characteristics[i].m_native); } }
Example 12
Source File: GattConnectDisconnectTests.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@Test public void filterConnectedDevicesAll() { // started FitbitGatt.getInstance().startGattClient(mockContext); Assert.assertTrue(FitbitGatt.getInstance().isInitialized()); UUID serviceUuidOne = UUID.fromString("5F1CBF47-4A8E-467F-9E55-BAFE00839CC1"); UUID serviceUuidTwo = UUID.fromString("528B080E-6608-403F-8F39-2246650751D0"); BluetoothGattService service1 = new BluetoothGattService(serviceUuidOne, BluetoothGattService.SERVICE_TYPE_PRIMARY); BluetoothGattService service2 = new BluetoothGattService(serviceUuidTwo, BluetoothGattService.SERVICE_TYPE_SECONDARY); // populate fake connected devices for (int i = 0; i < 4; i++) { String address = String.format(Locale.ENGLISH, "02:00:00:00:00:1%s", Integer.toString(i)); String name = String.format(Locale.ENGLISH, "fooDevice%s", i); FitbitBluetoothDevice device = new FitbitBluetoothDevice(address, name); GattConnection conn = new GattConnection(device, mockContext.getMainLooper()); conn.setMockMode(true); // for the purpose of this test we will just set connected to true conn.setState(GattState.CONNECTED); if (i % 2 == 0) { conn.addService(service1); } else { conn.addService(service2); } FitbitGatt.getInstance().putConnectionIntoDevices(device, conn); } // request matching conns ArrayList<UUID> services = new ArrayList<>(2); services.add(serviceUuidOne); List<GattConnection> conns = FitbitGatt.getInstance().getMatchingConnectionsForServices(services); Assert.assertEquals(2, conns.size()); }
Example 13
Source File: BleService.java From SweetBlue with GNU General Public License v3.0 | 5 votes |
private BleService(final UUID uuid, final BleCharacteristic[] characteristics, final boolean constructorOverloadEnabler2000) { final int serviceType = BluetoothGattService.SERVICE_TYPE_PRIMARY; m_native = new BluetoothGattService(uuid, serviceType); for( int i = 0; i < characteristics.length; i++ ) { m_native.addCharacteristic(characteristics[i].m_native); } }
Example 14
Source File: GattServerTests.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@BeforeClass public static void before() { Timber.plant(new Timber.DebugTree()); mockContext = InstrumentationRegistry.getInstrumentation().getContext(); main = new BluetoothGattService(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba"), BluetoothGattService.SERVICE_TYPE_PRIMARY); BluetoothGattCharacteristic txChar = new BluetoothGattCharacteristic(UUID.fromString("ADABFB01-6E7D-4601-BDA2-BFFAA68956BA"), BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED); main.addCharacteristic(txChar); BluetoothGattCharacteristic rxChar = new BluetoothGattCharacteristic(UUID.fromString("ADABFB02-6E7D-4601-BDA2-BFFAA68956BA"), BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED); main.addCharacteristic(rxChar); liveData = new BluetoothGattService(UUID.fromString("558dfa00-4fa8-4105-9f02-4eaa93e62980"), BluetoothGattService.SERVICE_TYPE_PRIMARY); BluetoothGattCharacteristic ldChar = new BluetoothGattCharacteristic(UUID.fromString("558DFA01-4FA8-4105-9F02-4EAA93E62980"), BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED); liveData.addCharacteristic(ldChar); dncs = new BluetoothGattService(UUID.fromString("16bcfd00-253f-c348-e831-0db3e334d580"), BluetoothGattService.SERVICE_TYPE_PRIMARY); BluetoothGattCharacteristic notifChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD02-253F-C348-E831-0DB3E334D580"), BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED | BluetoothGattCharacteristic.PERMISSION_WRITE); dncs.addCharacteristic(notifChar); cpChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD01-253F-C348-E831-0DB3E334D580"), BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE); dncs.addCharacteristic(cpChar); BluetoothGattCharacteristic flsChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD04-253F-C348-E831-0DB3E334D580"), BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE); dncs.addCharacteristic(flsChar); }
Example 15
Source File: AddGattServerServiceTransactionTest.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@Before public void before() { mockContext = InstrumentationRegistry.getInstrumentation().getContext(); services = new ArrayList<>(); services.add(new ParcelUuid(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba"))); service = new BluetoothGattService(services.get(0).getUuid(), BluetoothGattService.SERVICE_TYPE_PRIMARY); CountDownLatch cd = new CountDownLatch(1); NoOpGattCallback cb = new NoOpGattCallback() { @Override public void onGattServerStarted(GattServerConnection serverConnection) { super.onGattServerStarted(serverConnection); assertTrue(serverConnection.getServer().addService(service)); cd.countDown(); } }; FitbitGatt.getInstance().registerGattEventListener(cb); FitbitGatt.getInstance().startGattServer(mockContext); try { cd.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { fail("Timeout during test setup"); } if (cd.getCount() != 0) { fail("We have not added the service before the test"); } }
Example 16
Source File: GattDatabase.java From SweetBlue with GNU General Public License v3.0 | 5 votes |
/** * Builds the current {@link BluetoothGattService}, and returns the parent {@link GattDatabase}. */ public final GattDatabase build() { m_service = new BluetoothGattService(m_serviceUuid, m_isPrimary ? BluetoothGattService.SERVICE_TYPE_PRIMARY : BluetoothGattService.SERVICE_TYPE_SECONDARY); for (BluetoothGattCharacteristic ch : m_characteristics) { m_service.addCharacteristic(ch); } m_database.addService(m_service); return m_database; }
Example 17
Source File: GattDatabase.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
/** * Builds the current {@link BluetoothGattService}, and returns the parent {@link GattDatabase}. */ public final GattDatabase build() { m_service = new BluetoothGattService(m_serviceUuid, m_isPrimary ? BluetoothGattService.SERVICE_TYPE_PRIMARY : BluetoothGattService.SERVICE_TYPE_SECONDARY); for (BluetoothGattCharacteristic ch : m_characteristics) { m_service.addCharacteristic(ch); } m_database.addService(m_service); return m_database; }
Example 18
Source File: GattPlugin.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
private void addLocalGattServerService(DumperContext dumpContext, Iterator<String> args) throws InterruptedException { if (args.hasNext()) { String serviceUuid = args.next(); BluetoothGattServer server = fitbitGatt.getServer().getServer(); boolean isDuplicate = false; for (BluetoothGattService service : server.getServices()) { String currentUuid = service.getUuid().toString(); if (currentUuid.equals(serviceUuid)) { isDuplicate = true; break; } } if (!isDuplicate) { BluetoothGattService gattService = new BluetoothGattService(UUID.fromString(serviceUuid), BluetoothGattService.SERVICE_TYPE_PRIMARY); AddGattServerServiceTransaction tx = new AddGattServerServiceTransaction(fitbitGatt.getServer(), GattState.ADD_SERVICE_SUCCESS, gattService); CountDownLatch cdl = new CountDownLatch(1); fitbitGatt.getServer().runTx(tx, result -> { logSuccessOrFailure(result, dumpContext, "Successfully Added Gatt Server Service", "Failed Adding Gatt Server Service"); cdl.countDown(); }); cdl.await(); } else { logSuccess(dumpContext, "Duplicate service by UUID "); } } else { logError(dumpContext, new IllegalArgumentException("No viable service UUID provided")); } }
Example 19
Source File: GattPlugin.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
private void removeGattServerService(DumperContext dumpContext, Iterator<String> args) throws InterruptedException { if (args.hasNext()) { String serviceUuid = args.next(); BluetoothGattService gattService = new BluetoothGattService(UUID.fromString(serviceUuid), BluetoothGattService.SERVICE_TYPE_PRIMARY); RemoveGattServerServicesTransaction tx = new RemoveGattServerServicesTransaction(fitbitGatt.getServer(), GattState.ADD_SERVICE_SUCCESS, gattService); CountDownLatch cdl = new CountDownLatch(1); fitbitGatt.getServer().runTx(tx, result -> { logSuccessOrFailure(result, dumpContext, "Successfully Removed Gatt Server Service", "Failed Removing Gatt Server Service"); cdl.countDown(); }); cdl.await(); } else { logError(dumpContext, new IllegalArgumentException("No viable service UUID provided")); } }
Example 20
Source File: DiscoveryResultsAdapter.java From RxAndroidBle with Apache License 2.0 | 4 votes |
private String getServiceType(BluetoothGattService service) { return service.getType() == BluetoothGattService.SERVICE_TYPE_PRIMARY ? "primary" : "secondary"; }