当getBluetoothLeAdvertiser返回一个对象时,为什么isMultipleAdvertisementSupported()返回false? [英] Why isMultipleAdvertisementSupported() returns false, when getBluetoothLeAdvertiser returns an object?

查看:410
本文介绍了当getBluetoothLeAdvertiser返回一个对象时,为什么isMultipleAdvertisementSupported()返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在设备上进行BLE传输。

I am trying to play with BLE transmission on my device.

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

Here is the code I use and the output:

// 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

我不明白为什么 mBluetoothLeAdvertiser 不是 null ,因为 mBluetoothLeAdvertiser 验证它不是 false

I can not understand why mBluetoothLeAdvertiser is not null, since mBluetoothLeAdvertiser verifies that it is not 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;
}


推荐答案

欢迎来到Android世界,它同时是开放源代码和封闭源代码!您对上面的开源 BluetoothLeAdvertiser 代码的分析是正确的。如果该代码正在您的移动设备上运行,则您不会在顶部代码段中看到测试所显示的输出。 结论:第二个片段中显示的代码不能是设备上的代码。

Welcome to the world of Android, which is both open source and closed source at the same time! Your analysis of the open source BluetoothLeAdvertiser code above is correct. If that code is running on your mobile device, you would not see the output that your test in the top code snippet shows. Conclusion: the code shown in the second snippet must not be what is on the device.

Android设备OEM可以自由派发源代码并对其进行修改以使其与他们的硬件一起使用。在这种情况下,我知道摩托罗拉在此代码中为其Moto X和Moto G设备做了同样的事情。尽管 isMultipleAdvertisementSupported()返回false,这些设备仍返回 BluetoothLeAdvertiser 。一位摩托罗拉工程师向我解释说,他们改变了这一点,因为尽管使用了一次只能支持一个广告的BLE芯片,但他们仍希望支持广告。确实,我已经证实摩托罗拉设备可以播发广告,但是如果您尝试同时进行两个播发,它将失败。

Android device OEMs are free to fork the source code and modify it to make it work with their hardware. In this case, I know that Motorola did the same thing in this code for their Moto X and Moto G devices. These devices return a BluetoothLeAdvertiser despite the fact that isMultipleAdvertisementSupported() returns false. A Motorola engineer explained to me that they changed this because they wanted to support Advertising despite using a BLE chip that could support only one Advertisement at a time. Indeed, I have verified that Motorola devices can advertise, but if you try to get two advertisements going simultaneously, it fails.

这篇关于当getBluetoothLeAdvertiser返回一个对象时,为什么isMultipleAdvertisementSupported()返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆