Android5.0 BLE 周边(BluetoothLeAdvertiser)
<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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。