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

时间:2015-08-19 10:27:49

标签: 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

我无法理解为什么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;
}

1 个答案:

答案 0 :(得分:11)

欢迎来到Android的世界,它既是开源的又是闭源的!您对上述开源elements = [ { 'name': 'company_logo', 'type': 'I', 'x1': 20.0, 'y1': 17.0, 'x2': 78.0, 'y2': 30.0, 'font': None, 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text': 'logo', 'priority': 2, }, { 'name': 'company_name', 'type': 'T', 'x1': 17.0, 'y1': 32.5, 'x2': 115.0, 'y2': 37.5, 'font': 'Arial', 'size': 12.0, 'bold': 1, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text': '', 'priority': 2, }, { 'name': 'box', 'type': 'B', 'x1': 15.0, 'y1': 15.0, 'x2': 185.0, 'y2': 260.0, 'font': 'Arial', 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text': None, 'priority': 0, }, { 'name': 'box_x', 'type': 'B', 'x1': 95.0, 'y1': 15.0, 'x2': 105.0, 'y2': 25.0, 'font': 'Arial', 'size': 0.0, 'bold': 1, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text': None, 'priority': 2, }, { 'name': 'line1', 'type': 'L', 'x1': 100.0, 'y1': 25.0, 'x2': 100.0, 'y2': 57.0, 'font': 'Arial', 'size': 0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'I', 'text': None, 'priority': 3, }, ] #here we instantiate the template and define the HEADER f = Template(format="A4", elements=elements, title="Sample Invoice") f.add_page() #we FILL some of the fields of the template with the information we want #note we access the elements treating the template instance as a "dict" f["company_name"] = "Sample Company" f["company_logo"] = "pyfpdf/tutorial/logo.png" #and now we render the page f.render("./template.pdf") 代码的分析是正确的。如果该代码在您的移动设备上运行,您将看不到顶部代码段中的测试输出。 结论:第二个代码段中显示的代码不得为设备上的代码。

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