Codenameone 如何使用retrieveConnected方法?

Codenameone 如何使用retrieveConnected方法?,codenameone,Codenameone,我想知道如何使用蓝牙类中的retrieveConnected()方法。此类是CN1Bluetooth.cn1lib的一部分 我不知道如何用这种方法获得配对设备 不幸的是,没有关于使用这种方法的例子 编辑: 我使用了retrieveConnected(),正如您告诉我的: Button retco = new Button("Retrieve"); this.add(retco); retco.addActionListener(new ActionListener() {

我想知道如何使用
蓝牙
中的
retrieveConnected()
方法。此类是CN1Bluetooth.cn1lib的一部分

我不知道如何用这种方法获得配对设备

不幸的是,没有关于使用这种方法的例子

编辑: 我使用了retrieveConnected(),正如您告诉我的:

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)
ca.weblite.codename1.json.JSONException:JSONObject文本必须在[]的字符1处以“{”开头
位于ca.weblite.codename1.json.JSONTokener.syntaxError(JSONTokener.java:448)
位于ca.weblite.codename1.json.JSONObject.(JSONObject.java:176)
位于ca.weblite.codename1.json.JSONObject.(JSONObject.java:253)
atcom.codename1.cordova.CordovaCallbackManager.sendResult(CordovaCallbackManager.java:50)
位于com.codename1.cordova.CallbackContext.sendPluginResult(CallbackContext.java:26)
位于com.codename1.bluetoothle.BluetoothLePlugin.retrieveConnectedAction(BluetoothLePlugin.java:1212)
位于com.codename1.bluetoothle.BluetoothLePlugin.execute(BluetoothLePlugin.java:306)
位于com.codename1.cordova.CordovaPlugin.execute(CordovaPlugin.java:34)
在com.codename1.cordova.CordovaNativeImpl.execute(CordovaNativeImpl.java:14)
在com.codename1.cordova.cordovanivestub.execute(cordovanivestub.java:9)
位于com.codename1.cordova.cordova.execute(cordova.java:29)
位于com.codename1.bluetoothle.Bluetooth.retrieveConnected(Bluetooth.java:129)
位于be.ssii.app.forms.EidReader$3.actionPerformed(未知来源:97)
位于com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
位于com.codename1.ui.Button.fireActionEvent(Button.java:570)
位于com.codename1.ui.Button.released(Button.java:604)
位于com.codename1.ui.Button.pointerReleased(Button.java:708)
位于com.codename1.ui.Form.pointerReleased(Form.java:3369)
位于com.codename1.ui.Component.pointerReleased(Component.java:4552)
位于com.codename1.ui.Display.handleEvent(Display.java:2180)
在com.codename1.ui.Display.edtlopimpl(Display.java:1152)上
位于com.codename1.ui.Display.mainEDTLoop(Display.java:1070)
位于com.codename1.ui.runnablerrapper.run(runnablerrapper.java:120)
位于com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
运行(Thread.java:764)

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

该方法检索配对的蓝牙LE设备。在iOS中,“配对”的设备在正常扫描期间不会返回。回调为“即时”与scan.UUID过滤相比,它可能无法在Android上工作,因此它会返回所有配对的设备

bluetoothle.retrieveConnected(e -> { }, params);
params
值是用于筛选检索依据的服务ID数组。如果未指定服务ID,则不会返回任何设备

例如

如果成功,您应该得到一个设备对象数组

但是,看看这里的代码:

看起来这行是错误的,应该更改为:

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

plugin.execute("retrieveConnected", callack, callack, j.toString());
但我还没有测试过这个

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