当getBluetoothLeAdvertiser返回一个对象时,为什么isMultipleAdvertisementSupported()返回false?

LA_*_*LA_ 4 android sony ibeacon-android android-ibeacon android-ble

我正试图在我的设备上玩BLE传输.

这是我使用的代码和输出:

// check BLE support
Log.i(TAG, "BLE supported: " + getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)); // true

// check BLE transmission support
final BluetoothManager bluetoothManager =
        (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();

Log.i(TAG, "isMultipleAdvertisementSupported: " + mBluetoothAdapter.isMultipleAdvertisementSupported()); // false
Log.i(TAG, "isOffloadedFilteringSupported: " + mBluetoothAdapter.isOffloadedFilteringSupported()); // false
Log.i(TAG, "isOffloadedScanBatchingSupported: " + mBluetoothAdapter.isOffloadedScanBatchingSupported()); // false

BluetoothLeAdvertiser mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
Log.i(TAG, mBluetoothLeAdvertiser.toString()); //android.bluetooth.le.BluetoothLeAdvertiser@1c51f789

// check BLE transmission support
// android-beacon-library, https://github.com/AltBeacon/android-beacon-library
int result = BeaconTransmitter.checkTransmissionSupported(getApplicationContext());
Log.i(TAG, "ABL checkTransmissionSupported: " + result); // 0
Run Code Online (Sandbox Code Playgroud)

我无法理解为什么mBluetoothLeAdvertiser不是null,因为mBluetoothLeAdvertiser它验证它不是false:

package android.bluetooth;
// ...

public BluetoothLeAdvertiser getBluetoothLeAdvertiser() {
    if (getState() != STATE_ON) {
        return null;
    }
    if (!isMultipleAdvertisementSupported()) {
        return null;
    }
    synchronized(mLock) {
        if (sBluetoothLeAdvertiser == null) {
            sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService);
        }
    }
    return sBluetoothLeAdvertiser;
}

// ...

public boolean isMultipleAdvertisementSupported() {
    if (getState() != STATE_ON) return false;
    try {
        return mService.isMultiAdvertisementSupported();
    } catch (RemoteException e) {
        Log.e(TAG, "failed to get isMultipleAdvertisementSupported, error: ", e);
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

dav*_*ung 12

欢迎来到Android的世界,它既是开源的又是闭源的!您对上述开源BluetoothLeAdvertiser代码的分析是正确的.如果该代码在您的移动设备上运行,您将看不到顶部代码段中的测试输出.结论:第二个代码段中显示的代码不能是设备上的代码.

Android设备OEM可以自由分叉源代码并对其进行修改以使其与硬件配合使用.在这种情况下,我知道摩托罗拉在这个代码中为他们的Moto X和Moto G设备做了同样的事情.BluetoothLeAdvertiser尽管isMultipleAdvertisementSupported()返回false ,这些设备仍会返回.一位摩托罗拉工程师向我解释说他们改变了这一点,因为他们想要支持广告,尽管使用的BLE芯片一次只能支持一个广告.事实上,我已经证实摩托罗拉设备可以做广告,但如果你试图让两个广告同时进行,它就会失败.