Java Code Examples for android.bluetooth.le.AdvertiseSettings

The following are top voted examples for showing how to use android.bluetooth.le.AdvertiseSettings. 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: RangeThings   File: GattServer.java   Source Code and License 7 votes vote down vote up
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) return;

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(GattProfile.SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example 2
Project: mobly-bundled-snippets   File: JsonDeserializer.java   Source Code and License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static AdvertiseSettings jsonToBleAdvertiseSettings(JSONObject jsonObject)
        throws JSONException {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    if (jsonObject.has("AdvertiseMode")) {
        int mode = MbsEnums.BLE_ADVERTISE_MODE.getInt(jsonObject.getString("AdvertiseMode"));
        builder.setAdvertiseMode(mode);
    }
    // Timeout in milliseconds.
    if (jsonObject.has("Timeout")) {
        builder.setTimeout(jsonObject.getInt("Timeout"));
    }
    if (jsonObject.has("Connectable")) {
        builder.setConnectable(jsonObject.getBoolean("Connectable"));
    }
    if (jsonObject.has("TxPowerLevel")) {
        int txPowerLevel =
                MbsEnums.BLE_ADVERTISE_TX_POWER.getInt(jsonObject.getString("TxPowerLevel"));
        builder.setTxPowerLevel(txPowerLevel);
    }
    return builder.build();
}
 
Example 3
Project: Quick-Bluetooth-LE   File: BLEServer.java   Source Code and License 6 votes vote down vote up
public BtError startServer(){
	BtError error = checkBluetooth();
	if(error != BtError.None)
		return error;
	bleAdvertiser = btAdapter.getBluetoothLeAdvertiser();
	gattServer = btManager.openGattServer(context, gattServerCallback);
	for(BluetoothGattService service : services){
		gattServer.addService(service);
	}
	if(bleAdvertiser == null)
		return BtError.NoServer;
	AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
	settings.setAdvertiseMode(advertiseMode);
	settings.setConnectable(true);
	settings.setTimeout(0);
	settings.setTxPowerLevel(advertiseTransmitPower);
	AdvertiseData.Builder data = new AdvertiseData.Builder();
	data.setIncludeDeviceName(advertiseDeviceName);
	//data.addServiceUuid(new ParcelUuid(SERVICE_COMMUNICATION));
	bleAdvertiser.startAdvertising(settings.build(), data.build(), advertiseCallback);
	serverRunning = true;
	return BtError.None;
}
 
Example 4
Project: blefun-androidthings   File: GattServer.java   Source Code and License 6 votes vote down vote up
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example 5
Project: sample-bluetooth-le-gattserver   File: GattServerActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Begin advertising over Bluetooth that this device is connectable
 * and supports the Current Time Service.
 */
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(TimeProfile.TIME_SERVICE))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example 6
Project: BLEServerSimple   File: AdvertiseAdaptor.java   Source Code and License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private AdvertiseSettings makeAdvertiseSetting() {

    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();

    //Set advertise mode to control the advertising power and latency.
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);
    //Set advertise TX power level to control the transmission power level for the advertising.
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_ULTRA_LOW);
    //Set whether the advertisement type should be connectable or non-connectable.
    builder.setConnectable(CONNECTABLE);
    //Limit advertising to a given amount of time.
    builder.setTimeout(TIMEOUT);

    return builder.build();
}
 
Example 7
Project: BleUARTPeripheral   File: MainActivity.java   Source Code and License 6 votes vote down vote up
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) return;

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .addServiceUuid(new ParcelUuid(UARTProfile.UART_SERVICE))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example 8
Project: unity-bluetooth   File: BLEServicePeripheral.java   Source Code and License 6 votes vote down vote up
@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 9
Project: Quick-Bluetooth-LE   File: BLEServer.java   Source Code and License 6 votes vote down vote up
public BtError startServer(){
	BtError error = checkBluetooth();
	if(error != BtError.None)
		return error;
	bleAdvertiser = btAdapter.getBluetoothLeAdvertiser();
	gattServer = btManager.openGattServer(context, gattServerCallback);
	for(BluetoothGattService service : services){
		gattServer.addService(service);
	}
	if(bleAdvertiser == null)
		return BtError.NoServer;
	AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
	settings.setAdvertiseMode(advertiseMode);
	settings.setConnectable(true);
	settings.setTimeout(0);
	settings.setTxPowerLevel(advertiseTransmitPower);
	AdvertiseData.Builder data = new AdvertiseData.Builder();
	data.setIncludeDeviceName(advertiseDeviceName);
	//data.addServiceUuid(new ParcelUuid(SERVICE_COMMUNICATION));
	bleAdvertiser.startAdvertising(settings.build(), data.build(), advertiseCallback);
	serverRunning = true;
	return BtError.None;
}
 
Example 10
Project: Mycroft-Android   File: BeaconUtil.java   Source Code and License 6 votes vote down vote up
public void broadcastAsBeacon() {
        Beacon beacon = new Beacon.Builder()
                .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
                .setId2("1")
                .setId3("2")
                .setManufacturer(0x0118) // Radius Networks.  Change this for other beacon layouts
                .setTxPower(-59)
                .setDataFields(Arrays.asList(new Long[]{0l})) // Remove this for beacon layouts without d: fields
                .build();
// Change the layout below for other beacon types
        BeaconParser beaconParser = new BeaconParser()
                .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(context, beaconParser);
        beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {

            @Override
            public void onStartFailure(int errorCode) {
                Log.e("Class", "Advertisement start failed with code: " + errorCode);
            }

            @Override
            public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                Log.i("class", "Advertisement start succeeded.");
            }
        });
    }
 
Example 11
Project: beacons-android   File: EddystoneGattConfigurator.java   Source Code and License 6 votes vote down vote up
@SuppressLint("InlinedApi")
@Override
public int setAdvertiseInterval(int advertiseIntervalMs) {
    Util.log(TAG, "setAdvertiseInterval() called with: advertiseIntervalMs = [" + advertiseIntervalMs + "]");

    @Advertiser.Mode int mode;

    if (advertiseIntervalMs <= 100 + (250 - 100) / 2) {
        // 100 ms
        mode = AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY;
    } else if (advertiseIntervalMs >= 1000 - (1000 - 250) / 2) {
        // 1000 ms
        mode = AdvertiseSettings.ADVERTISE_MODE_LOW_POWER;
    } else {
        // 250 ms actually
        mode = AdvertiseSettings.ADVERTISE_MODE_BALANCED;
    }

    if (mode != getModifiedOrOriginalBeacon().getAdvertiseMode()) {
        // restarting a beacon destroys the GATT connection, make sure we use a stopped clone
        getOrCloneConfiguredBeacon().edit().setAdvertiseMode(mode).apply();
    }

    return getAdvertiseInterval();
}
 
Example 12
Project: SweetBlue   File: NativeUtil.java   Source Code and License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setToAdvertising(BleManager mgr, final AdvertiseSettings settings, L_Util.AdvertisingCallback callback, Interval delay)
{
    if (Utils.isLollipop())
    {
        L_UtilBridge.setAdvListener(callback);
        mgr.getPostManager().postToUpdateThreadDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                L_Util.getNativeAdvertisingCallback().onStartSuccess(settings);
            }
        }, delay.millis());
    }
}
 
Example 13
Project: mDL-ILP   File: BLEConnection.java   Source Code and License 5 votes vote down vote up
private void startAdvertising() {
    AdvertiseSettings advSettings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .setConnectable(true)
            .build();

    AdvertiseData advData = new AdvertiseData.Builder()
            .setIncludeTxPowerLevel(true)
            .addServiceUuid(Constants.SERVICE_pUUID)
            .addServiceData(Constants.SERVICE_pUUID, serviceData)
            .build();

    AdvertiseData advScanResponse = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .build();

    if (mAdvertiser != null) {
        gattService.startAdvertising();
        mAdvertiser.startAdvertising(advSettings, advData, advScanResponse, advCallback);
        Log.d(TAG, "Started advertisement of mDL service with data " + new String(serviceData));
    } else {
        Log.e(TAG, "mAdvertiser not available!");
    }
}
 
Example 14
Project: IBeaconBroadcastDemo   File: MainActivity.java   Source Code and License 5 votes vote down vote up
public AdvertiseSettings createAdvertiseSettings(boolean connectable, int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    builder.setConnectable(connectable);
    builder.setTimeout(timeoutMillis);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
}
 
Example 15
Project: IBeaconBroadcastDemo   File: MainActivity.java   Source Code and License 5 votes vote down vote up
public void onStartSuccess(android.bluetooth.le.AdvertiseSettings settingsInEffect) {
    if (settingsInEffect != null) {
        Log.d("debug", "onStartSuccess TxPowerLv="
                + settingsInEffect.getTxPowerLevel()
                + " mode=" + settingsInEffect.getMode()
                + " timeout=" + settingsInEffect.getTimeout());
    } else {
        Log.d("debug", "onStartSuccess, settingInEffect is null");
    }
    switchView.setChecked(true);
    setProgressBarIndeterminateVisibility(false);
}
 
Example 16
Project: mobly-bundled-snippets   File: JsonSerializer.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Bundle serializeBleAdvertisingSettings(AdvertiseSettings advertiseSettings) {
    Bundle result = new Bundle();
    result.putString(
            "TxPowerLevel",
            MbsEnums.BLE_ADVERTISE_TX_POWER.getString(advertiseSettings.getTxPowerLevel()));
    result.putString(
            "Mode", MbsEnums.BLE_ADVERTISE_MODE.getString(advertiseSettings.getMode()));
    result.putInt("Timeout", advertiseSettings.getTimeout());
    result.putBoolean("IsConnectable", advertiseSettings.isConnectable());
    return result;
}
 
Example 17
Project: mobly-bundled-snippets   File: MbsEnums.java   Source Code and License 5 votes vote down vote up
private static RpcEnum buildBleAdvertiseTxPowerEnum() {
    RpcEnum.Builder builder = new RpcEnum.Builder();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return builder.build();
    }
    return builder.add(
                    "ADVERTISE_TX_POWER_ULTRA_LOW",
                    AdvertiseSettings.ADVERTISE_TX_POWER_ULTRA_LOW)
            .add("ADVERTISE_TX_POWER_LOW", AdvertiseSettings.ADVERTISE_TX_POWER_LOW)
            .add("ADVERTISE_TX_POWER_MEDIUM", AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .add("ADVERTISE_TX_POWER_HIGH", AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
            .build();
}
 
Example 18
Project: mobly-bundled-snippets   File: MbsEnums.java   Source Code and License 5 votes vote down vote up
private static RpcEnum buildBleAdvertiseModeEnum() {
    RpcEnum.Builder builder = new RpcEnum.Builder();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return builder.build();
    }
    return builder.add("ADVERTISE_MODE_BALANCED", AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .add("ADVERTISE_MODE_LOW_LATENCY", AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
            .add("ADVERTISE_MODE_LOW_POWER", AdvertiseSettings.ADVERTISE_MODE_LOW_POWER)
            .build();
}
 
Example 19
Project: mobly-bundled-snippets   File: BluetoothLeAdvertiserSnippet.java   Source Code and License 5 votes vote down vote up
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    Log.e("Bluetooth LE advertising started with settings: " + settingsInEffect.toString());
    SnippetEvent event = new SnippetEvent(mCallbackId, "onStartSuccess");
    Bundle advertiseSettings =
            JsonSerializer.serializeBleAdvertisingSettings(settingsInEffect);
    event.getData().putBundle("SettingsInEffect", advertiseSettings);
    sEventCache.postEvent(event);
}
 
Example 20
Project: react-native-ibeacon-simulator   File: BeaconBroadcast.java   Source Code and License 5 votes vote down vote up
@ReactMethod
public void startSharedAdvertisingBeaconWithString(String uuid, int major, int minor,String identifier) {
int manufacturer = 0x4C;
Beacon beacon = new Beacon.Builder()
		.setId1(uuid)
		.setId2(String.valueOf(major))
		.setId3(String.valueOf(minor))
		.setManufacturer(manufacturer)
		.setBluetoothName(identifier)
		.setTxPower(-59)
		.build();
BeaconParser beaconParser = new BeaconParser()
		.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
this.beaconTransmitter = new BeaconTransmitter(context, beaconParser);
this.beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {

	@Override
	public void onStartFailure(int errorCode) {
		Log.d("ReactNative", "Error from start advertising " + errorCode);
	}

	@Override
	public void onStartSuccess(AdvertiseSettings settingsInEffect) {
		Log.d("ReactNative", "Success start advertising");
	}
});
}
 
Example 21
Project: noise   File: BluetoothSyncService.java   Source Code and License 5 votes vote down vote up
private AdvertiseSettings buildAdvertiseSettings() {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
    builder.setTimeout(0); // Advertise as long as Bluetooth is on, blatantly ignoring Google's advice.
    builder.setConnectable(false);
    return builder.build();
}
 
Example 22
Project: BLE-HID-Peripheral-for-Android   File: HidPeripheral.java   Source Code and License 5 votes vote down vote up
/**
 * Starts advertising
 */
public final void startAdvertising() {
    handler.post(new Runnable() {
        @Override
        public void run() {
            // set up advertising setting
            final AdvertiseSettings advertiseSettings = new AdvertiseSettings.Builder()
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .build();

            // set up advertising data
            final AdvertiseData advertiseData = new Builder()
                    .setIncludeTxPowerLevel(false)
                    .setIncludeDeviceName(true)
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            // set up scan result
            final AdvertiseData scanResult = new Builder()
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            Log.d(TAG, "advertiseData: " + advertiseData + ", scanResult: " + scanResult);
            bluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, scanResult, advertiseCallback);
        }
    });
}
 
Example 23
Project: mesh-core-on-android   File: JniCallbacks.java   Source Code and License 5 votes vote down vote up
private AdvertiseSettings createAdvSettings(boolean connectable, int timeoutMillis) {
AdvertiseSettings.Builder mSettingsbuilder = new AdvertiseSettings.Builder();
mSettingsbuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
mSettingsbuilder.setConnectable(connectable);
mSettingsbuilder.setTimeout(timeoutMillis);
mSettingsbuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
AdvertiseSettings mAdvertiseSettings = mSettingsbuilder.build();
if(mAdvertiseSettings == null){
	if(D){
		Log.e(TAG,"mAdvertiseSettings == null");
	}
}
return mAdvertiseSettings;
}
 
Example 24
Project: mesh-core-on-android   File: JniCallbacks.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
	super.onStartSuccess(settingsInEffect);
	if (settingsInEffect == null) {
		Log.e(TAG, "onStartSuccess, settingInEffect is null");
	}
}
 
Example 25
Project: coinblesk-client-gui   File: BluetoothLEServer.java   Source Code and License 5 votes vote down vote up
private void startAdvertisingService(final UUID uuid) {
    if (bluetoothLeAdvertiseCallbacks == null) {
        bluetoothLeAdvertiseCallbacks = new ArrayList<>();
    }

    AdvertiseCallback advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            Log.d(TAG, "BLE advertising - uuid: " + uuid.toString()
                    + " - onStartSuccess - settings: " + settingsInEffect.toString());
        }

        @Override
        public void onStartFailure(int errorCode) {
            Log.w(TAG, "BLE advertising - uuid: " + uuid.toString()
                    + " - onStartFailure - errorCode=" + errorCode);
        }
    };
    bluetoothLeAdvertiseCallbacks.add(advertiseCallback);

    bluetoothAdapter.getBluetoothLeAdvertiser().startAdvertising(
            new AdvertiseSettings.Builder()
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .build(),
            new AdvertiseData.Builder()
                    .setIncludeDeviceName(false)
                    .addServiceUuid(new ParcelUuid(uuid))
                    .build(),
            advertiseCallback
    );
}
 
Example 26
Project: AsteroidOSSync   File: P_Task_Advertise.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect)
{
    getLogger().d("Advertising started successfully.");
    getServer().invokeAdvertiseListeners(BleServer.AdvertisingListener.Status.SUCCESS, m_listener);
    succeed();
}
 
Example 27
Project: AsteroidOSSync   File: BleAdvertisingPacket.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
/*package*/ AdvertiseSettings getNativeSettings(BleAdvertisingMode mode, BleTransmissionPower power, Interval timeout) {
    AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
    settings.setAdvertiseMode(mode.getNativeMode());
    settings.setTxPowerLevel(power.getNativeMode());
    settings.setConnectable(isConnectable());
    settings.setTimeout((int) timeout.millis());
    return settings.build();
}
 
Example 28
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 29
Project: BLE-Mesh   File: BLEPeripheral.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    if (settingsInEffect != null) {
        Timber.d("Advertise success TxPowerLv="
                + settingsInEffect.getTxPowerLevel()
                + " mode=" + settingsInEffect.getMode());
    } else {
        Timber.d("Advertise success");
    }
}
 
Example 30
Project: BLE-Mesh   File: BLEPeripheral.java   Source Code and License 5 votes vote down vote up
private AdvertiseSettings createAdvSettings() {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    builder.setConnectable(true);
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    return builder.build();
}
 
Example 31
Project: beacons-android   File: Advertiser.java   Source Code and License 5 votes vote down vote up
public Advertiser(SettingsProvider provider) {
        mAdvertiseSettings = new AdvertiseSettings.Builder()
                .setAdvertiseMode(provider.getAdvertiseMode())
                .setTxPowerLevel(provider.getTxPowerLevel())
                .setConnectable(provider.isConnectable())
                // oups! https://code.google.com/p/android/issues/detail?id=232219
//                .setTimeout(provider.getTimeout())
                .build();
    }
 
Example 32
Project: beacons-android   File: Advertiser.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    mStatus = STATUS_RUNNING;
    mSettingsInEffect = settingsInEffect;

    // on start or restart, rebase the clock time used for PDU count estimation
    mLastPDUUpdateTime = SystemClock.elapsedRealtime();

    if (null != mAdvertisersManager) {
        mAdvertisersManager.onAdvertiserStarted(this);
    }
}
 
Example 33
Project: beacons-android   File: EddystoneGattConfigurator.java   Source Code and License 5 votes vote down vote up
@Override
public int getAdvertiseInterval() {
    switch (getModifiedOrOriginalBeacon().getAdvertiseMode()) {
        case AdvertiseSettings.ADVERTISE_MODE_LOW_POWER:
        default:
            return 1000;
        case AdvertiseSettings.ADVERTISE_MODE_BALANCED:
            return 250;
        case AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY:
            return 100;
    }
}
 
Example 34
Project: uriio-android   File: Uriio.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an UriioBeacon beacon based on the provided URL registration result.
 * @param urlResource         URL registration info
 * @param beaconTimeToLive    Initial value for the beacon's TTL for issuing ephemeral short URLs.
 * @return A new beaoon, without saving or starting it. You can adjust any other beacon properties and save it.
 */
@NonNull
public static UriioBeacon createBeacon(UrlResource urlResource, int beaconTimeToLive) {
    return new UriioBeacon(urlResource.getId(), urlResource.getToken(),
            beaconTimeToLive, urlResource.getUrl(),
            AdvertiseSettings.ADVERTISE_MODE_BALANCED,
            AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
}
 
Example 35
Project: DeviceConnect-Android   File: AbstractHOGPServer.java   Source Code and License 5 votes vote down vote up
/**
 * アドバタイジングを開始します.
 */
private void startAdvertising() {
    if (DEBUG) {
        Log.d(TAG, "startAdvertising");
    }

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            // set up advertising setting
            final AdvertiseSettings advertiseSettings = new AdvertiseSettings.Builder()
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .build();

            // set up advertising data
            final AdvertiseData advertiseData = new AdvertiseData.Builder()
                    .setIncludeTxPowerLevel(false)
                    .setIncludeDeviceName(true)
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            // set up scan result
            final AdvertiseData scanResult = new AdvertiseData.Builder()
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            mBluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, scanResult, mAdvertiseCallback);
        }
    });
}
 
Example 36
Project: ble-android-sdk   File: LBleAdvertiser.java   Source Code and License 5 votes vote down vote up
@Override
public void startAdvertising(String uuid, List<ScanResult> closestBeaconId, String fallbackUrl) {
    stopAdvertising();
    advertiser.startAdvertising(
            new AdvertiseSettings.Builder().setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED).build(),
            new AdvertiseData.Builder().addServiceUuid(ParcelUuid.fromString(uuid)).build(),
            callback
    );
}
 
Example 37
Project: Scatterbrain   File: BleUtil.java   Source Code and License 5 votes vote down vote up
public static AdvertiseSettings createAdvSettings(int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    builder.setConnectable(true);
    builder.setTimeout(timeoutMillis);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
}
 
Example 38
Project: SweetBlue   File: L_Util.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect)
{
    if (m_userAdvCallback != null)
    {
        m_userAdvCallback.onStartSuccess(fromNativeSettings(settingsInEffect));
    }
}
 
Example 39
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 40
Project: SweetBlue   File: BleAdvertisingPacket.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
/*package*/ AdvertiseSettings getNativeSettings(BleAdvertisingMode mode, BleTransmissionPower power, Interval timeout) {
    AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
    settings.setAdvertiseMode(mode.getNativeMode());
    settings.setTxPowerLevel(power.getNativeMode());
    settings.setConnectable(isConnectable());
    settings.setTimeout((int) timeout.millis());
    return settings.build();
}
 
Example 41
Project: SweetBlue   File: P_AndroidBluetoothManager.java   Source Code and License 5 votes vote down vote up
@Override
public final void startAdvertising(AdvertiseSettings settings, AdvertiseData adData, L_Util.AdvertisingCallback callback)
{
    if (!L_Util.startAdvertising(m_adaptor, settings, adData, callback))
    {
        m_bleManager.ASSERT(false, "Unable to start advertising!");
        m_bleManager.getLogger().e("Failed to start advertising!");
    }
}
 
Example 42
Project: physical-web   File: FatBeaconBroadcastService.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings advertiseSettings) {
  Utils.createBroadcastNotification(FatBeaconBroadcastService.this, stopServiceReceiver,
      BROADCASTING_NOTIFICATION_ID, getString(R.string.fatbeacon_notification_title),
      mDisplayInfo, "fatBeaconFilter");
  if (!mStartedByRestart) {
    Toast.makeText(getApplicationContext(), R.string.fatbeacon_broadcasting_confirmation,
        Toast.LENGTH_LONG).show();
  }
}
 
Example 43
Project: physical-web   File: FatBeaconBroadcastService.java   Source Code and License 5 votes vote down vote up
private void broadcastUrl() {
  byte[] bytes = null;
  try {
    bytes = mDisplayInfo.getBytes("UTF-8");
  } catch (UnsupportedEncodingException e) {
    Log.e(TAG, "Could not encode URL", e);
    return;
  }
  AdvertiseData advertiseData = AdvertiseDataUtils.getFatBeaconAdvertisementData(bytes);
  AdvertiseSettings advertiseSettings = AdvertiseDataUtils.getAdvertiseSettings(true);
  mBluetoothLeAdvertiser.stopAdvertising(mAdvertiseCallback);
  mBluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, mAdvertiseCallback);
}
 
Example 44
Project: physical-web   File: PhysicalWebBroadcastService.java   Source Code and License 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings advertiseSettings) {
    Log.d(TAG, "URL is broadcasting");
    Utils.createBroadcastNotification(PhysicalWebBroadcastService.this, stopServiceReceiver,
        BROADCASTING_NOTIFICATION_ID, getString(R.string.broadcast_notif), mDisplayUrl,
        "myFilter");
    if (!mStartedByRestart) {
        Toast.makeText(getApplicationContext(), getString(R.string.url_broadcast),
            Toast.LENGTH_LONG).show();
    }
}
 
Example 45
Project: physical-web   File: PhysicalWebBroadcastService.java   Source Code and License 5 votes vote down vote up
private void broadcastUrl(byte[] url) {
    final AdvertiseData advertisementData = AdvertiseDataUtils.getAdvertisementData(url);
    final AdvertiseSettings advertiseSettings = AdvertiseDataUtils.getAdvertiseSettings(false);
    mBluetoothLeAdvertiser.stopAdvertising(mAdvertiseCallback);
    mBluetoothLeAdvertiser.startAdvertising(advertiseSettings,
        advertisementData, mAdvertiseCallback);
}
 
Example 46
Project: physical-web   File: AdvertiseDataUtils.java   Source Code and License 5 votes vote down vote up
@TargetApi(21)
public static AdvertiseSettings getAdvertiseSettings(boolean connectable) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
    builder.setConnectable(connectable);

    return builder.build();
}
 
Example 47
Project: mobly-bundled-snippets   File: BluetoothLeAdvertiserSnippet.java   Source Code and License 4 votes vote down vote up
/**
 * Start Bluetooth LE advertising.
 *
 * <p>This can be called multiple times, and each call is associated with a {@link
 * AdvertiseCallback} object, which is used to stop the advertising.
 *
 * @param callbackId
 * @param advertiseSettings A JSONObject representing a {@link AdvertiseSettings object}. E.g.
 *     <pre>
 *          {
 *            "AdvertiseMode": "ADVERTISE_MODE_BALANCED",
 *            "Timeout": (int, milliseconds),
 *            "Connectable": (bool),
 *            "TxPowerLevel": "ADVERTISE_TX_POWER_LOW"
 *          }
 *     </pre>
 *
 * @param advertiseData A JSONObject representing a {@link AdvertiseData} object. E.g.
 *     <pre>
 *          {
 *            "IncludeDeviceName": (bool),
 *            # JSON list, each element representing a set of service data, which is composed of
 *            # a UUID, and an optional string.
 *            "ServiceData": [
 *                      {
 *                        "UUID": (A string representation of {@link ParcelUuid}),
 *                        "Data": (Optional, The string representation of what you want to
 *                                 advertise, base64 encoded)
 *                        # If you want to add a UUID without data, simply omit the "Data"
 *                        # field.
 *                      }
 *                ]
 *          }
 *     </pre>
 *
 * @throws BluetoothLeAdvertiserSnippetException
 * @throws JSONException
 */
@RpcMinSdk(Build.VERSION_CODES.LOLLIPOP_MR1)
@AsyncRpc(description = "Start BLE advertising.")
public void bleStartAdvertising(
        String callbackId, JSONObject advertiseSettings, JSONObject advertiseData)
        throws BluetoothLeAdvertiserSnippetException, JSONException {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        throw new BluetoothLeAdvertiserSnippetException(
                "Bluetooth is disabled, cannot start BLE advertising.");
    }
    AdvertiseSettings settings = JsonDeserializer.jsonToBleAdvertiseSettings(advertiseSettings);
    AdvertiseData data = JsonDeserializer.jsonToBleAdvertiseData(advertiseData);
    AdvertiseCallback advertiseCallback = new DefaultAdvertiseCallback(callbackId);
    mAdvertiser.startAdvertising(settings, data, advertiseCallback);
    mAdvertiseCallbacks.put(callbackId, advertiseCallback);
}
 
Example 48
Project: RangeThings   File: GattServer.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    Log.i(TAG, "Peripheral Advertise Started.");
}
 
Example 49
Project: blefun-androidthings   File: GattServer.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    Log.i(TAG, "LE Advertise Started.");
}
 
Example 50
Project: freeu2f-android   File: U2FService.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    super.onStartSuccess(settingsInEffect);
    Log.d(getClass().getCanonicalName(), "Advertising started...");
}
 
Example 51
Project: sample-bluetooth-le-gattserver   File: GattServerActivity.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    Log.i(TAG, "LE Advertise Started.");
}
 
Example 52
Project: BleUARTPeripheral   File: MainActivity.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    Log.i(TAG, "Peripheral Advertise Started.");
    postStatusMessage("GATT Server Ready");
}
 
Example 53
Project: AsteroidOSSync   File: UnitTestManagerLayer.java   Source Code and License 4 votes vote down vote up
@Override
public void startAdvertising(AdvertiseSettings settings, AdvertiseData adData, AdvertiseCallback callback)
{
}
 
Example 54
Project: unity-bluetooth   File: BLEServicePeripheral.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
    super.onStartSuccess(settingsInEffect);
}
 
Example 55
Project: AndroidBluttoothMasterAndSlave   File: BLEAdvertiser.java   Source Code and License 4 votes vote down vote up
private void initAdvertiseData() {
    //初始化Advertise的设定
    Context mContext = contextWeakReference.get();
    if (mContext == null) {
        prepared = false;
        return;
    }
    BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    advertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            super.onStartSuccess(settingsInEffect);
            Log.d(TAG, "["+
                    Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
                    Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
                    Thread.currentThread().getStackTrace()[2].getMethodName() + "]");
            Log.i(TAG, "onStartSuccess success");

            advertiseResultListener.onAdvertiseSuccess();

            if (settingsInEffect != null) {
                Log.d(TAG, "onStartSuccess TxPowerLv=" + settingsInEffect.getTxPowerLevel() + " mode=" + settingsInEffect.getMode()
                        + " timeout=" + settingsInEffect.getTimeout());
            } else {
                Log.e(TAG, "onStartSuccess, settingInEffect is null");
            }
            Log.i(TAG, "onStartSuccess settingsInEffect" + settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            super.onStartFailure(errorCode);
            Log.e(TAG, "Advertise failed.Error code: " + errorCode);
            advertiseResultListener.onAdvertiseFailed(errorCode);
        }
    };
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);//ADVERTISE_MODE_BALANCED origin
    settingsBuilder.setConnectable(true);
    settingsBuilder.setTimeout(0);
    settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);// ADVERTISE_TX_POWER_MEDIUM origin
    advertiseSettings = settingsBuilder.build();
    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    dataBuilder.setIncludeDeviceName(true);
    dataBuilder.addServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE));
    advertiseData = dataBuilder.build();
    prepared = true;
}
 
Example 56
Project: Android-BLE-Library   File: BLEAdvertiser.java   Source Code and License 4 votes vote down vote up
private void initAdvertiseData() {
    //初始化Advertise的设定
    Context mContext = contextWeakReference.get();
    if (mContext == null) {
        prepared = false;
        return;
    }
    BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    advertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            super.onStartSuccess(settingsInEffect);
            Log.i(TAG, "Advertise success");

            advertiseResultListener.onAdvertiseSuccess();

            if (settingsInEffect != null) {
                Log.d(TAG, "onStartSuccess TxPowerLv=" + settingsInEffect.getTxPowerLevel() + " mode=" + settingsInEffect.getMode()
                        + " timeout=" + settingsInEffect.getTimeout());
            } else {
                Log.e(TAG, "onStartSuccess, settingInEffect is null");
            }
            Log.i(TAG, "onStartSuccess settingsInEffect" + settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            super.onStartFailure(errorCode);
            Log.e(TAG, "Advertise failed.Error code: " + errorCode);
            advertiseResultListener.onAdvertiseFailed(errorCode);
        }
    };
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    settingsBuilder.setConnectable(true);
    settingsBuilder.setTimeout(0);
    settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
    advertiseSettings = settingsBuilder.build();
    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    dataBuilder.setIncludeDeviceName(true);
    dataBuilder.addServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE));
    advertiseData = dataBuilder.build();
    prepared = true;
}
 
Example 57
Project: Bluetooth-LE-Server   File: BLEPeripheral.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect){
    Log.d("advertise","onStartSuccess");
}
 
Example 58
Project: beacons-android   File: Advertiser.java   Source Code and License 4 votes vote down vote up
public AdvertiseSettings getAdvertiseSettings() {
    return mAdvertiseSettings;
}
 
Example 59
Project: beacons-android   File: Advertiser.java   Source Code and License 4 votes vote down vote up
public AdvertiseSettings getSettingsInEffect() {
    return mSettingsInEffect;
}
 
Example 60
Project: ble-test-peripheral-android   File: Peripheral.java   Source Code and License 4 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
  super.onStartSuccess(settingsInEffect);
  Log.v(TAG, "Broadcasting");
  mAdvStatus.setText(R.string.status_advertising);
}