2

As described in the API reference in Android L which is available here: https://developer.android.com/preview/reference.html

There are two ways to start advertising data in Android L using Bluetooth Low Energy:

  1. public void startAdvertising (AdvertiseSettings settings, AdvertisementData advertiseData, AdvertiseCallback callback)

  2. public void startAdvertising (AdvertiseSettings settings, AdvertisementData advertiseData, AdvertisementData scanResponse, AdvertiseCallback callback)

The second method contains one more param: scanResponse

When I use the first method, everything works fine, and I could scanned the information set in the advertiseData. However, when I test the second method, I could only scan and get the data in scanResponse, and from the LogCat, I got the following error: enter image description here

enter image description here

It seems to be a bluetooth buffer issue, and in my (advertise)callback object, I log a sentence:

advertiseCallback = new AdvertiseCallback() {
            @Override
            public void onSuccess(AdvertiseSettings advertiseSettings) {

                Log.i(TAG, "Adv Success");
                // Other operations
            }

            @Override
            public void onFailure(int i) {
                // Other operations
            }
        };

It can be seen from LogCat that the onSuccess() method is called twice, and I think it could be either of the following two reasons: 1. advertiseData and the scanResponse data, while the advertiseData may have caused the bluetooth problem, thus it could not be broadcasted; 2. advertiseData is closed (successfully) after it starts (successfully) (probably);

Did I use this method in a wrong way? I use the Nexus 5 with Android L Preview edition, or it is the bug for the current Android system?

Reference:

Method: public void startAdvertising (AdvertiseSettings settings, AdvertisementData advertiseData, AdvertisementData scanResponse, AdvertiseCallback callback)

Start Bluetooth LE Advertising. The advertiseData would be broadcasted after the operation succeeds. The scanResponse would be returned when the scanning device sends active scan request. Method returns immediately, the operation status are delivered through callback.

Requires BLUETOOTH_ADMIN

Parameters

settings Settings for Bluetooth LE advertising.

advertiseData Advertisement data to be advertised in advertisement packet.

scanResponse Scan response associated with the advertisement data.

callback Callback for advertising status.

MrEngineer13
  • 38,642
  • 13
  • 74
  • 93
Torrence
  • 448
  • 3
  • 20

0 Answers0