Вопрос

I want to make an android app using Bluetooth, and after some research I came across this ANE. I haven't ever used an ANE, but from what I understand its implementation is very similar to using a SWC. After copying the ANE to the .\lib path and including it in my project, I tried scanning for devices as suggested on the website:

if (Bluetooth.isSupported) {
                trace("1!");
                bt = Bluetooth.currentAdapter();
                trace("2!");
                bt.addEventListener(BluetoothScanEvent.BLUETOOTH_DISCOVERY_STARTED, bluetoothScanEventHandeler);
                bt.addEventListener(BluetoothScanEvent.BLUETOOTH_DEVICE_FOUND, bluetoothScanEventHandeler);
                bt.addEventListener(BluetoothScanEvent.BLUETOOTH_DISCOVERY_FINISHED, bluetoothScanEventHandeler);
                bt.scanForVisibleDevices();
            }

For some reason I get the error

Error #1009: Cannot access a property or method of a null object reference.

The traces I included point to bt = Bluetooth.currentAdapter(); but if I change Bluetooth.isSupported to Bluetooth.isSupported() then I get the same error there.
I've made sure that the project's Adobe AIR Application Descriptor File Template (application xmlns) matches the ANE's.
No one else seems to have the same problem, help?

Это было полезно?

Решение

I see that you are using flash develop which I am not familiar with but it sounds like BlueTooth is null. Usually ANEs are singletons and have a getInstance() method. Once you create your single instance, BlueTooth should no longer be null and you should be able to access the rest of its methods.

In your project you would usually access the ANE like..

var blueTooth:BlueTooth = Bluetooth.getInstance();
if(BlueTooth.isSupported)
{
}

or

if(BlueTooth.isSupported)
{
   bt = BlueTooth.getInstance().currentAdapter();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top