use of android.bluetooth.le.AdvertiseSettings in project physical-web by google.
the class FatBeaconBroadcastService method broadcastUrl.
// ///////////////////////////////
// utilities
// ///////////////////////////////
// Broadcast via bluetooth the stored URL
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);
}
use of android.bluetooth.le.AdvertiseSettings in project sample-bluetooth-le-gattserver by androidthings.
the class GattServerActivity method startAdvertising.
/**
* 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);
}
use of android.bluetooth.le.AdvertiseSettings in project android-beacon-library by AltBeacon.
the class BluetoothMedic method runTransmitterTest.
/**
* Starts up a beacon transmitter with the intent of seeing if it results in an error condition
* indicating the bluetooth stack may be in a bad state.
*
* If the failure error code matches a pattern known to be associated with a bad bluetooth stack
* state, then the bluetooth stack is turned off and then back on after a short delay in order
* to try to recover.
*
* @return false if the test indicates a failure indicating a bad state of the bluetooth stack
*/
@SuppressWarnings({ "unused", "WeakerAccess" })
@RequiresApi(21)
public boolean runTransmitterTest(final Context context) {
initializeWithContext(context);
this.mTransmitterTestResult = null;
long testStartTime = System.currentTimeMillis();
if (mAdapter != null) {
final BluetoothLeAdvertiser advertiser = getAdvertiserSafely(mAdapter);
if (advertiser != null) {
AdvertiseSettings settings = (new Builder()).setAdvertiseMode(0).build();
AdvertiseData data = (new android.bluetooth.le.AdvertiseData.Builder()).addManufacturerData(0, new byte[] { 0 }).build();
LogManager.i(TAG, "Starting transmitter test");
advertiser.startAdvertising(settings, data, new AdvertiseCallback() {
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
LogManager.i(BluetoothMedic.TAG, "Transmitter test succeeded");
advertiser.stopAdvertising(this);
BluetoothMedic.this.mTransmitterTestResult = true;
}
public void onStartFailure(int errorCode) {
super.onStartFailure(errorCode);
LogManager.d(BluetoothMedic.TAG, "Sending onStartFailure event");
BluetoothMedic.this.processMedicAction("onStartFailed", errorCode);
if (errorCode == 4) {
BluetoothMedic.this.mTransmitterTestResult = false;
LogManager.w(BluetoothMedic.TAG, "Transmitter test failed in a way we consider a test failure");
} else {
BluetoothMedic.this.mTransmitterTestResult = true;
LogManager.i(BluetoothMedic.TAG, "Transmitter test failed, but not in a way we consider a test failure");
}
}
});
} else {
LogManager.d(TAG, "Cannot get advertiser");
}
while (this.mTransmitterTestResult == null) {
LogManager.d(TAG, "Waiting for transmitter test to complete...");
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
/* do nothing */
}
if (System.currentTimeMillis() - testStartTime > 5000L) {
LogManager.d(TAG, "Timeout running transmitter test");
break;
}
}
}
LogManager.d(TAG, "transmitter test complete");
return this.mTransmitterTestResult != null && this.mTransmitterTestResult;
}
use of android.bluetooth.le.AdvertiseSettings in project physical-web by google.
the class PhysicalWebBroadcastService method broadcastUrl.
// ///////////////////////////////
// utilities
// ///////////////////////////////
// Broadcast via bluetooth the stored URL
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);
}
Aggregations