标签:android style blog http io ar color os sp
<span style="font-size:18px;">/**
* Returns a {@link BluetoothLeAdvertiser} object for Bluetooth LE Advertising operations, o<span style="white-space:pre"> </span>r
* null if Bluetooth LE Advertising is not support on this device.
* <p>
* Use {@link #isMultipleAdvertisementSupported()} to check whether LE Advertising is suppor<span style="white-space:pre"> </span>ted
* on this device before calling this method.
*/
public BluetoothLeAdvertiser getBluetoothLeAdvertiser() {
if (getState() != STATE_ON) {
return null;
}
if (!isMultipleAdvertisementSupported()) {
return null;
}
synchronized(mLock) {
if (sBluetoothLeAdvertiser == null) {
sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService);
}
}
return sBluetoothLeAdvertiser;
}
</span><span style="font-size:18px;"> final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
BluetoothLeAdvertiser advertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
AdvertiseData data = new AdvertiseData.Builder()
.addServiceUuid(ParcelUuid.fromString(ADVERTISER_SERVICE_UUID)).build();
AdvertiseSettings settings = new AdvertiseSettings.Builder().setConnectable(true).build();
advertiser.startAdvertising(settings , data, new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
}
});</span>
Android5.0 BLE 周边(BluetoothLeAdvertiser)
标签:android style blog http io ar color os sp
原文地址:http://blog.csdn.net/songzeyang99/article/details/41727023