如何使用检索方法



我想知道如何使用Bluetooth classretrieveConnected()方法。此类是cn1bluetooth.cn1lib的一部分。

我不知道如何使用此方法获取配对设备。

不幸的是,没有关于使用此方法的示例。

编辑:我告诉我要做的(

),我使用了检索()
Button retco = new Button("Retrieve");
    this.add(retco);
    retco.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                debug("Action performed 1: "+ev);
                debug("Bt: "+bt);
                ArrayList ar = new ArrayList();
                //ar.add("180D");
                debug("array: "+ar);
                bt.retrieveConnected(
                        new ActionListener() {
                            public void actionPerformed(ActionEvent ev) {
                                debug("actionPerformed : " + ev);
                                main.add(new SpanLabel("TEST 3"));
                                debug("ev.getSource() = " + ev.getSource());
                                JSONObject res = (JSONObject)ev.getSource();
                                debug("RES = " + res);
                                try {
                                    updateUI(res);
                                } catch (JSONException e) {
                                    // TODO Auto-generated catch block
                                    debug(e.getMessage());
                                }
                            };
                        },ar);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                debug(e.getMessage());
            }
        }
    });
private void updateUI(JSONObject obj) throws JSONException {
    this.add(new SpanLabel(obj.toString()));
    this.add(new SpanLabel("TEST"));
    this.revalidate();
}

但是我有这些错误消息

ca.weblite.codename1.json.JSONException: A JSONObject text must begin with '{' at character 1 of []
at ca.weblite.codename1.json.JSONTokener.syntaxError(JSONTokener.java:448)
at ca.weblite.codename1.json.JSONObject.<init>(JSONObject.java:176)
at ca.weblite.codename1.json.JSONObject.<init>(JSONObject.java:253)
atcom.codename1.cordova.CordovaCallbackManager.sendResult(CordovaCallbackManager.java:50)
at com.codename1.cordova.CallbackContext.sendPluginResult(CallbackContext.java:26)
at com.codename1.bluetoothle.BluetoothLePlugin.retrieveConnectedAction(BluetoothLePlugin.java:1212)
at com.codename1.bluetoothle.BluetoothLePlugin.execute(BluetoothLePlugin.java:306)
at com.codename1.cordova.CordovaPlugin.execute(CordovaPlugin.java:34)
at com.codename1.cordova.CordovaNativeImpl.execute(CordovaNativeImpl.java:14)
at com.codename1.cordova.CordovaNativeStub.execute(CordovaNativeStub.java:9)
at com.codename1.cordova.Cordova.execute(Cordova.java:29)
at com.codename1.bluetoothle.Bluetooth.retrieveConnected(Bluetooth.java:129)
at be.ssii.app.forms.EidReader$3.actionPerformed(Unknown Source:97)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
at com.codename1.ui.Button.fireActionEvent(Button.java:570)
at com.codename1.ui.Button.released(Button.java:604)
at com.codename1.ui.Button.pointerReleased(Button.java:708)
at com.codename1.ui.Form.pointerReleased(Form.java:3369)
at com.codename1.ui.Component.pointerReleased(Component.java:4552)
at com.codename1.ui.Display.handleEvent(Display.java:2180)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1152)
at com.codename1.ui.Display.mainEDTLoop(Display.java:1070)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:764)

有一个与设备配对的设备,它使用该应用程序,但没有检测到配对的设备。它应该可以工作,配对设备是一个BLE设备。

取回的配对蓝牙LE设备。在iOS中,"配对"的设备在正常扫描过程中不会返回。与扫描相比,回调是"即时"。UUID过滤可能在Android上不起作用,因此它返回所有配对的BLE设备。

bluetoothle.retrieveConnected(e -> { }, params);

params值是用于过滤检索的服务ID数组。如果未指定服务ID,则不会返回设备。

,例如

ArrayList a = new ArrayList();
a.add("180D");
a.add("180F");

成功,您应该得到一系列设备对象。

但是,在这里查看代码:https://github.com/chen-fishbein/bluetoothle-codenameone/blob/master/cn1bluethooth/src/codename1/bluetootle/bluetoothle/bluetooth.java#l135

看起来这条线是错误的,应该从中更改:

plugin.execute("retrieveConnected", j.toString(), callack);

plugin.execute("retrieveConnected", callack, callack, j.toString());

,但我没有测试过。

最新更新