BluetoothLeAdvertiser AdvertiseCallback 抛出 ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
BluetoothLeAdvertiser AdvertiseCallback throws ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
我有创建广告的代码:
private void startLeAdvertise() {
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
.setConnectable(true)
.setTimeout(ADVERTISE_TIMEOUT)
.build();
AdvertiseData data = new AdvertiseData.Builder()
.addServiceUuid(new ParcelUuid(UUID.fromString(BEACON_SERVICE)))
.build();
mAdvertiseCallback = new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
Log.i(TAG, "======= onStartSuccess:");
Log.i(TAG, settingsInEffect.toString());
}
@Override
public void onStartFailure(int errorCode) {
super.onStartFailure(errorCode);
String description = "";
if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED) {
description = "ADVERTISE_FAILED_FEATURE_UNSUPPORTED";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
description = "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
description = "ADVERTISE_FAILED_ALREADY_STARTED";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE) {
description = "ADVERTISE_FAILED_DATA_TOO_LARGE";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR) {
description = "ADVERTISE_FAILED_INTERNAL_ERROR";
} else {
description = "unknown";
}
Log.i(TAG, "error: " + description);
}
};
mBluetoothLeAdvertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
无论什么我总是得到
ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
我正在测试
一加X (ONE E1003)
- API 5.1.1;
- 氧气 2.2.0;
- 内核 3.4.0-pref+;
连结 5
-API6.0.1;
- 内核 3.4.0-g7717f76;
(有趣的是,使用 Nexus 我得到 isMultipleAdvertisementSupported == false
所以它也不起作用...)
编辑 - 这个模型工作得很好:
银河 S6 (SM-G920F)
- API 5.1.1;
- 内核 3.10.61-5816106;
我最初的问题是,为什么我总是得到 ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
。现在我发现它适用于 S6 但不适用于 Nexus 5 我可以假设什么?是 manufacturer/hardware 问题还是 OS 版本问题?谢谢。
在 运行 对其他设备进行更多测试后,我发现这是实现它的正确方法,但它只适用于少数芯片组。有关此技术的更多信息,请参见:Chipsets/Devices supporting Android 5 BLE peripheral mode
我有创建广告的代码:
private void startLeAdvertise() {
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
.setConnectable(true)
.setTimeout(ADVERTISE_TIMEOUT)
.build();
AdvertiseData data = new AdvertiseData.Builder()
.addServiceUuid(new ParcelUuid(UUID.fromString(BEACON_SERVICE)))
.build();
mAdvertiseCallback = new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
Log.i(TAG, "======= onStartSuccess:");
Log.i(TAG, settingsInEffect.toString());
}
@Override
public void onStartFailure(int errorCode) {
super.onStartFailure(errorCode);
String description = "";
if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED) {
description = "ADVERTISE_FAILED_FEATURE_UNSUPPORTED";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
description = "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
description = "ADVERTISE_FAILED_ALREADY_STARTED";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE) {
description = "ADVERTISE_FAILED_DATA_TOO_LARGE";
} else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR) {
description = "ADVERTISE_FAILED_INTERNAL_ERROR";
} else {
description = "unknown";
}
Log.i(TAG, "error: " + description);
}
};
mBluetoothLeAdvertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
无论什么我总是得到
ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
我正在测试
一加X (ONE E1003)
- API 5.1.1;
- 氧气 2.2.0;
- 内核 3.4.0-pref+;
连结 5
-API6.0.1;
- 内核 3.4.0-g7717f76;
(有趣的是,使用 Nexus 我得到 isMultipleAdvertisementSupported == false
所以它也不起作用...)
编辑 - 这个模型工作得很好:
银河 S6 (SM-G920F)
- API 5.1.1;
- 内核 3.10.61-5816106;
我最初的问题是,为什么我总是得到 ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
。现在我发现它适用于 S6 但不适用于 Nexus 5 我可以假设什么?是 manufacturer/hardware 问题还是 OS 版本问题?谢谢。
在 运行 对其他设备进行更多测试后,我发现这是实现它的正确方法,但它只适用于少数芯片组。有关此技术的更多信息,请参见:Chipsets/Devices supporting Android 5 BLE peripheral mode