2

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.

GuilhE
  • 11,591
  • 16
  • 75
  • 116

1 Answers1

0

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

Community
  • 1
  • 1
GuilhE
  • 11,591
  • 16
  • 75
  • 116