Java Code Examples for android.bluetooth.le.BluetoothLeAdvertiser

The following are top voted examples for showing how to use android.bluetooth.le.BluetoothLeAdvertiser. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: beacons-android   File: Advertiser.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Project: AsteroidOSSync   File: P_AndroidBluetoothManager.java   Source Code and License 5 votes vote down vote up
@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!");
    }
}
 
Example 3
Project: AsteroidOSSync   File: P_AndroidBluetoothManager.java   Source Code and License 5 votes vote down vote up
@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!");
    }
}
 
Example 4
Project: beacons-android   File: Advertiser.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Project: swan-sense-studio   File: BLEManager.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 6
Project: SweetBlue   File: L_Util.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 7
Project: SweetBlue   File: L_Util.java   Source Code and License 5 votes vote down vote up
public static void stopAdvertising(BluetoothAdapter adapter)
{
    if (adapter != null)
    {
        final BluetoothLeAdvertiser adv = adapter.getBluetoothLeAdvertiser();
        if (adv != null)
        {
            adv.stopAdvertising(m_nativeAdvertiseCallback);
        }
    }
}
 
Example 8
Project: BLEServerSimple   File: AdvertiseAdaptor.java   Source Code and License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private BluetoothLeAdvertiser getAdvertiser(BluetoothAdapter adapter) {
    return adapter.getBluetoothLeAdvertiser();
}
 
Example 9
Project: AsteroidOSSync   File: L_Util.java   Source Code and License 4 votes vote down vote up
public static BluetoothLeAdvertiser getBluetoothLeAdvertiser(BluetoothAdapter adapter)
{
    return adapter.getBluetoothLeAdvertiser();
}
 
Example 10
Project: SweetBlue   File: L_Util.java   Source Code and License 4 votes vote down vote up
public static BluetoothLeAdvertiser getBluetoothLeAdvertiser(BluetoothAdapter adapter)
{
    return adapter.getBluetoothLeAdvertiser();
}