BluetoothLeAdvertiser AdvertiseCallback throws ADVERTISE_FAILED_TOO_MANY_ADVERTISERS

好久不见. 提交于 2019-12-12 18:35:52

问题


I have this code to create an 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);
}

No matter what I always get

ADVERTISE_FAILED_TOO_MANY_ADVERTISERS

I'm testing with
One Plus X (ONE E1003)
- API 5.1.1;
- Oxygen 2.2.0;
- Kernel 3.4.0-pref+;

Nexus 5
- API 6.0.1;
- Kernel 3.4.0-g7717f76;

(funny thing, with Nexus I get isMultipleAdvertisementSupported == false so it doesn't work either...)

EDIT - With this model works just fine:

Galaxy S6 (SM-G920F)
- API 5.1.1;
- Kernel 3.10.61-5816106;

My original question was, why I'm always getting ADVERTISE_FAILED_TOO_MANY_ADVERTISERS. Now that I found that it works with S6 but not with Nexus 5 what can I assume? Is it a manufacturer/hardware problem or OS version? Thanks.


回答1:


After running more tests with other devices I found out that this is the proper way to implement it but it will only work with a few chipsets. More information about this technology here: Chipsets/Devices supporting Android 5 BLE peripheral mode



来源:https://stackoverflow.com/questions/35158037/bluetoothleadvertiser-advertisecallback-throws-advertise-failed-too-many-adverti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!