/** * Attempt to start BLE advertising. * @param bleAdvertiser BLE advertiser * @return True if no exception occurred while trying to start advertising. */ boolean start(BluetoothLeAdvertiser bleAdvertiser) { try { bleAdvertiser.startAdvertising(getAdvertiseSettings(), getAdvertiseData(), getAdvertiseScanResponse(), this); } catch (IllegalStateException e) { // tried to start advertising after Bluetooth was turned off // let upper level notice that BT is off instead of reporting an error if (BuildConfig.DEBUG) { Log.e(TAG, "start", e); } return false; } return true; }
@Override public final void startAdvertising(AdvertiseSettings settings, AdvertiseData adData, AdvertiseCallback callback) { final BluetoothLeAdvertiser ad = L_Util.getBluetoothLeAdvertiser(m_adaptor); if (ad != null) { ad.startAdvertising(settings, adData, callback); } else { m_bleManager.getLogger().e("Tried to start advertising, but the BluetoothLeAdvertiser was null!"); } }
@Override public final void stopAdvertising(AdvertiseCallback callback) { final BluetoothLeAdvertiser ad = L_Util.getBluetoothLeAdvertiser(m_adaptor); if (ad != null) { ad.stopAdvertising(callback); } else { m_bleManager.getLogger().e("Tried to stop advertising, but the BluetoothLeAdvertiser was null!"); } }
/** * Mark the advertiser as stopped and attempt to actually stop BLE advertisements. * @param bleAdvertiser BLE advertiser, or null * @return True if there was no error while trying to stop the Bluetooth advertiser. */ boolean stop(BluetoothLeAdvertiser bleAdvertiser) { updateEstimatedPDUCount(); mStatus = STATUS_STOPPED; if (null != bleAdvertiser) { bleAdvertiser.stopAdvertising(this); } return true; }
private void advertise() throws ExpressionParseException { final BluetoothLeAdvertiser bleAdvertiser = btAdapter.getBluetoothLeAdvertiser(); AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder().setIncludeDeviceName(true); for(Map.Entry<String, String> expressionEntry : registeredExpressions.entrySet()) { SensorValueExpression svExpression = (SensorValueExpression) ExpressionFactory.parse(expressionEntry.getValue()); String sensorValuePath = svExpression.getEntity() + ":" + svExpression.getValuePath(); UUID serviceUuid = getUuidForSensorValuePath(sensorValuePath); dataBuilder.addServiceUuid(new ParcelUuid(serviceUuid)); } bleAdvertiser.startAdvertising(advertiseSettings, dataBuilder.build(), advertisingCallback); }
public static boolean startAdvertising(BluetoothAdapter adapter, AdvertiseSettings settings, AdvertiseData adData, AdvertisingCallback callback) { final BluetoothLeAdvertiser adv = adapter.getBluetoothLeAdvertiser(); if (adv == null) return false; m_userAdvCallback = callback; adv.startAdvertising(settings, adData, m_nativeAdvertiseCallback); return true; }
public static void stopAdvertising(BluetoothAdapter adapter) { if (adapter != null) { final BluetoothLeAdvertiser adv = adapter.getBluetoothLeAdvertiser(); if (adv != null) { adv.stopAdvertising(m_nativeAdvertiseCallback); } } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private BluetoothLeAdvertiser getAdvertiser(BluetoothAdapter adapter) { return adapter.getBluetoothLeAdvertiser(); }
public static BluetoothLeAdvertiser getBluetoothLeAdvertiser(BluetoothAdapter adapter) { return adapter.getBluetoothLeAdvertiser(); }