可能的原因是调用stopAdvertisingSet()方法后仍然继续广告,这可能是由于Android BLE库的一个Bug或者在代码实现中没有正确调用stopAdvertisingSet()方法。以下是一些可能有用的步骤来解决该问题:
mBluetoothLeAdvertiser.stopAdvertisingSet(mAdvCallback);
...
@Override
public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int txPower, AdvertisingSetCallback .AdvertisingSetCallbackErrorCode status) {
Log.i(TAG, "Advertising data set: status=" + status);
if (status == AdvertisingSetCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
Log.e(TAG, "Advertise failed already started");
} else {
Log.i(TAG, "Advertisement stopped");
}
}
mBluetoothLeAdvertiser.getOwnBluetoothAddress();
mBluetoothLeAdvertiser.clearAdvertisingSets();
...
AdvertisingSetParameters parameters = new AdvertisingSetParameters.Builder()
.setLegacyMode(true)
.setConnectable(true)
.setIncludeTxPowerLevel(true)
.build();
AdvertiseData data = new AdvertiseData.Builder()
.setIncludeDeviceName(true)
.setIncludeTxPowerLevel(true)
.build();
mBluetoothLeAdvertiser.startAdvertisingSet(parameters, data, null, null, null, mAdvCallback);
通过上面的步骤,您可以将Android BLE stopAdvertisingSet()方法正常工作。