android.bluetooth.le.AdvertiseSettings Java Examples

The following examples show how to use android.bluetooth.le.AdvertiseSettings. 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: AdvertiserRequest.java    From Android-BLE with Apache License 2.0 7 votes vote down vote up
private void setAdvertiserSettings(){
    mAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mAdvertiser == null) {
        try {
            throw new AdvertiserUnsupportException("Device does not support Avertise!");
        } catch (AdvertiserUnsupportException e) {
            e.printStackTrace();
        }
    }
    //设置频率:  ADVERTISE_MODE_LOW_LATENCY 100ms     ADVERTISE_MODE_LOW_POWER 1s     ADVERTISE_MODE_BALANCED  250ms
    myAdvertiseSettings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)//设置广播间隔100ms
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
            .build();
}
 
Example #2
Source File: AdvertiserRequest.java    From Android-BLE with Apache License 2.0 6 votes vote down vote up
public void startAdvertising(final byte[] payload, final AdvertiseSettings advertiseSettings){
    if (bluetoothAdapter.isEnabled()){
        mHandler.removeCallbacks(stopAvertiseRunnable);
        if(mAdvertiser != null){
            ThreadUtils.asyn(new Runnable() {
                @Override
                public void run() {
                    mAdvertiser.stopAdvertising(mAdvertiseCallback);
                    myAdvertiseData = new AdvertiseData.Builder()
                            .addManufacturerData(65520, payload)
                            .setIncludeDeviceName(true)
                            .build();
                    mAdvertiser.startAdvertising(advertiseSettings, myAdvertiseData, mAdvertiseCallback);
                }
            });
        }
    }
}
 
Example #3
Source File: BLEServicePeripheral.java    From unity-bluetooth with MIT 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 #4
Source File: AdvertiserService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Starts BLE Advertising.
 */
private void startAdvertising() {
    goForeground();

    Log.d(TAG, "Service: Starting Advertising");

    if (mAdvertiseCallback == null) {
        AdvertiseSettings settings = buildAdvertiseSettings();
        AdvertiseData data = buildAdvertiseData();
        mAdvertiseCallback = new SampleAdvertiseCallback();

        if (mBluetoothLeAdvertiser != null) {
            mBluetoothLeAdvertiser.startAdvertising(settings, data,
                mAdvertiseCallback);
        }
    }
}
 
Example #5
Source File: EddystoneGattConfigurator.java    From beacons-android with Apache License 2.0 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 #6
Source File: JsonDeserializer.java    From mobly-bundled-snippets with Apache License 2.0 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 #7
Source File: AdvertiserService.java    From android-BluetoothAdvertisements with Apache License 2.0 6 votes vote down vote up
/**
 * Starts BLE Advertising.
 */
private void startAdvertising() {
    goForeground();

    Log.d(TAG, "Service: Starting Advertising");

    if (mAdvertiseCallback == null) {
        AdvertiseSettings settings = buildAdvertiseSettings();
        AdvertiseData data = buildAdvertiseData();
        mAdvertiseCallback = new SampleAdvertiseCallback();

        if (mBluetoothLeAdvertiser != null) {
            mBluetoothLeAdvertiser.startAdvertising(settings, data,
                mAdvertiseCallback);
        }
    }
}
 
Example #8
Source File: GattServer.java    From blefun-androidthings with Apache License 2.0 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 #9
Source File: NativeUtil.java    From SweetBlue with GNU General Public License v3.0 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 #10
Source File: GattServerActivity.java    From sample-bluetooth-le-gattserver with Apache License 2.0 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 #11
Source File: L_Util.java    From SweetBlue with GNU General Public License v3.0 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 #12
Source File: Advertiser.java    From beacons-android with Apache License 2.0 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 #13
Source File: EddystoneGattConfigurator.java    From beacons-android with Apache License 2.0 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 #14
Source File: AbstractHOGPServer.java    From DeviceConnect-Android with MIT 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 #15
Source File: AdvertiserService.java    From android-BluetoothAdvertisements with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an AdvertiseSettings object set to use low power (to help preserve battery life)
 * and disable the built-in timeout since this code uses its own timeout runnable.
 */
private AdvertiseSettings buildAdvertiseSettings() {
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
    settingsBuilder.setTimeout(0);
    return settingsBuilder.build();
}
 
Example #16
Source File: L_Util.java    From SweetBlue with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect)
{
    if (m_userAdvCallback != null)
    {
        m_userAdvCallback.onStartSuccess(fromNativeSettings(settingsInEffect));
    }
}
 
Example #17
Source File: Advertiser.java    From beacons-android with Apache License 2.0 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 #18
Source File: BleAdvertisingPacket.java    From SweetBlue with GNU General Public License v3.0 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 #19
Source File: P_AndroidBluetoothManager.java    From SweetBlue with GNU General Public License v3.0 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 #20
Source File: MainActivity.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
void advertise() {
    BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
    //define the power settings  could use ADVERTISE_MODE_LOW_POWER, ADVERTISE_MODE_BALANCED too.
    AdvertiseSettings settings = new AdvertiseSettings.Builder()
        .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
        .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
        .setConnectable(false)
        .build();

    ParcelUuid pUuid = new ParcelUuid(UUID.fromString(getString(R.string.ble_uuid)));

    AdvertiseData data = new AdvertiseData.Builder()
        .setIncludeDeviceName(false)
        .addServiceUuid(pUuid)
        .addServiceData(pUuid, "LE Demo".getBytes(Charset.forName("UTF-8")))
        .build();
    AdvertiseCallback advertisingCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            super.onStartSuccess(settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            Log.e("BLE", "Advertising onStartFailure: " + errorCode);
            super.onStartFailure(errorCode);
        }
    };

    advertiser.startAdvertising(settings, data, advertisingCallback);
    //advertiser.stopAdvertising(advertisingCallback);
}
 
Example #21
Source File: AdvertiseFragment.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
/**
 * start advertise
 * setup the power levels, the UUID, and the data
 * which is used the callback then call start advertising.
 */
private void start_advertise() {

    //define the power settings  could use ADVERTISE_MODE_LOW_POWER, ADVERTISE_MODE_BALANCED too.
    AdvertiseSettings settings = new AdvertiseSettings.Builder()
        .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
        .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
        .setConnectable(false)
        .build();
    //get the UUID needed.
    ParcelUuid pUuid = new ParcelUuid(UUID.fromString(getString(R.string.blue_uuid)));
    //build
    AdvertiseData data = new AdvertiseData.Builder()
        .setIncludeDeviceName(false)  //should be true, but we are bigger then 31bytes in the name?
        .addServiceUuid(pUuid)
        //this is where the text is added.
        .addServiceData(pUuid, text.getText().toString().getBytes(Charset.forName("UTF-8")))
        .build();
    advertisingCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            logthis("Advertising has started");
            logthis("message is " + text.getText().toString());
            advertising = true;
            advertise.setText("Stop Advertising");
            super.onStartSuccess(settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            logthis("Advertising onStartFailure: " + errorCode);
            advertising = false;
            advertise.setText("Start Advertising");
            super.onStartFailure(errorCode);
        }
    };

    advertiser.startAdvertising(settings, data, advertisingCallback);

}
 
Example #22
Source File: FatBeaconBroadcastService.java    From physical-web with Apache License 2.0 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 #23
Source File: FatBeaconBroadcastService.java    From physical-web with Apache License 2.0 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 #24
Source File: PhysicalWebBroadcastService.java    From physical-web with Apache License 2.0 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 #25
Source File: PhysicalWebBroadcastService.java    From physical-web with Apache License 2.0 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 #26
Source File: AdvertiseDataUtils.java    From physical-web with Apache License 2.0 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 #27
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void advertise() {
        BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();

        AdvertiseSettings settings = new AdvertiseSettings.Builder()
                .setAdvertiseMode( AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY )
                .setTxPowerLevel( AdvertiseSettings.ADVERTISE_TX_POWER_HIGH )
                .setConnectable(false)
                .build();

        ParcelUuid pUuid = new ParcelUuid( UUID.fromString( getString( R.string.ble_uuid ) ) );

        AdvertiseData data = new AdvertiseData.Builder()
                .setIncludeDeviceName( true )
                .addServiceUuid( pUuid )
                .addServiceData( pUuid, "Data".getBytes(Charset.forName("UTF-8") ) )
                .build();

        AdvertiseCallback advertisingCallback = new AdvertiseCallback() {
            @Override
            public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                super.onStartSuccess(settingsInEffect);
            }

            @Override
            public void onStartFailure(int errorCode) {
                Log.e( "BLE", "Advertising onStartFailure: " + errorCode );
                super.onStartFailure(errorCode);
            }
        };

        advertiser.startAdvertising( settings, data, advertisingCallback );
}
 
Example #28
Source File: MbsEnums.java    From mobly-bundled-snippets with Apache License 2.0 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 #29
Source File: BeaconBroadcast.java    From react-native-ibeacon-simulator with MIT 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 #30
Source File: BluetoothLeAdvertiserSnippet.java    From mobly-bundled-snippets with Apache License 2.0 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);
}