我有这个代码来创建一个Advertise:
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
我正在测试
One Plus X(ONE E1003)
- API 5.1.1;
- 氧气2.2.0;
- 内核3.4.0-pref +;
Nexus 5
- API 6.0.1;
- 内核3.4.0-g7717f76;
(有趣的是,Nexus我得isMultipleAdvertisementSupported == false
所以它也不起作用......)
编辑 - 使用此模型可以正常运行:
Galaxy S6(SM-G920F)
- API 5.1.1;
- 内核3.10.61-5816106;
我原来的问题是,为什么我总是得到ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
。既然我发现它适用于S6但不适用于Nexus 5我能想到什么?是制造商/硬件问题还是操作系统版本?谢谢。
答案 0 :(得分:0)
在使用其他设备运行更多测试后,我发现这是实现它的正确方法,但它只适用于少数芯片组。有关此技术的更多信息,请访问:Chipsets/Devices supporting Android 5 BLE peripheral mode