Codenameone 为什么我从不在本机接口中输入特定的回调函数?

Codenameone 为什么我从不在本机接口中输入特定的回调函数?,codenameone,Codenameone,我正在制作一个应用程序,它必须检测蓝牙读卡器,以及是否插入或从该读卡器中移除了一张卡 我在本机接口中使用了一个用于android部分的API,因此我从一个接口实现了两个回调函数,该接口涉及蓝牙读卡器检测,另外两个回调函数涉及蓝牙读卡器中的卡检测 检测到蓝牙读卡器时调用的两个回调函数,以及插入或从设备中取出卡时调用的另外两个回调函数 我对检测到蓝牙读卡器时调用的回调没有问题,但应用程序从不调用插入或移除卡时必须调用的函数 public class FtReaderNativeImpl implem

我正在制作一个应用程序,它必须检测蓝牙读卡器,以及是否插入或从该读卡器中移除了一张卡

我在本机接口中使用了一个用于android部分的API,因此我从一个接口实现了两个回调函数,该接口涉及蓝牙读卡器检测,另外两个回调函数涉及蓝牙读卡器中的卡检测

检测到蓝牙读卡器时调用的两个回调函数,以及插入或从设备中取出卡时调用的另外两个回调函数

我对检测到蓝牙读卡器时调用的回调没有问题,但应用程序从不调用插入或移除卡时必须调用的函数

public class FtReaderNativeImpl implements BluetoothRead.CardListener,BluetoothRead.ReaderListener{

    private BluetoothRead btRead;
    ArrayList<BluetoothDevice> listRead;

    public String scanBluetooth(){
        String chaine ="";
        if (Looper.myLooper() == null)
        { 
          Looper.prepare();
        }
        Log.p("btread avant init:"+btRead);
        btRead = new 

     BluetoothRead(com.codename1.impl.android.AndroidNativeUtil.getContext());
     btRead.setCardListener(this);
     btRead.setReaderListener(this);
     ReturnCode rc = btRead.btInitLib();
     Log.p("btread après init:"+btRead);
     Log.p("rc:"+rc);
     return chaine;
    }
       @Override
       public void CardInserted()
       {
                //showMessage("onCardInserted");
                String chaine=""; 
                //Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(), "INSERTED", Toast.LENGTH_SHORT).show();
                chaine+=btRead.getName();
                chaine+=btRead.getFirstName();
                eidReader.showDialog("INSERTED "+chaine);
                Log.p("btInsertOK");
       }

       @Override
       public void CardRemoved()
       {
                   String chaine=""; 
                   //Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(), "REMOVED", Toast.LENGTH_SHORT).show();
                   EidReader.showDialog("REMOVED "+chaine);
                   Log.p("btRemoveNOK");
       }

       @Override
       public void ReaderConnected(BluetoothDevice bluetoothDevice) 
       {
           /*Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(), "CONNECTED", Toast.LENGTH_SHORT).show();*/
          EidReader.showDialog("CONNECTED");
          Log.p("onReaderConnected: " + bluetoothDevice.getName());
          if (btRead.btOpen(bluetoothDevice) == ReturnCode.OK) {
             Log.p("btOpen OK");

          } else {
             Log.p("btOpen NOK");
          }
          Log.p("btread après listener:"+btRead);
       }

       @Override
       public void ReaderDisconnected(BluetoothDevice bluetoothDevice) 
       {
          //Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(), "DISCONNECTED", Toast.LENGTH_SHORT).show();
           EidReader.showDialog("DISCONNECTED");
       }}
公共类FtReaderNativeImpl实现BluetoothRead.CardListener、BluetoothRead.ReaderListener{
私人蓝牙阅读;
ArrayList listRead;
公共字符串{
字符串chaine=“”;
if(Looper.myLooper()==null)
{ 
Looper.prepare();
}
Log.p(“btread avant init:+btread”);
btRead=新
BluetoothRead(com.codename1.impl.android.AndroidNativeUtil.getContext());
btRead.setCardListener(这个);
btRead.setReaderListener(本文件);
ReturnCode rc=btRead.btInitLib();
Log.p(“btread après init:+btread”);
Log.p(“rc:+rc”);
返回链;
}
@凌驾
公共许可证
{
//showMessage(“onCardInserted”);
字符串chaine=“”;
//Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(),“INSERTED”,Toast.LENGTH\u SHORT.show();
chaine+=btRead.getName();
chaine+=btRead.getFirstName();
显示对话框(“插入的”+链接);
Log.p(“btInsertOK”);
}
@凌驾
已删除公共文件()
{
字符串chaine=“”;
//Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(),“已删除”,Toast.LENGTH\u SHORT.show();
显示对话框(“已删除”+链接);
Log.p(“btRemoveNOK”);
}
@凌驾
已连接公共无效读卡器(BluetoothDevice BluetoothDevice)
{
/*Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(),“CONNECTED”,Toast.LENGTH_SHORT).show()*/
EidReader.showDialog(“已连接”);
Log.p(“onReaderConnected:+bluetoothDevice.getName());
if(btRead.btOpen(蓝牙设备)=ReturnCode.OK){
Log.p(“btOpen OK”);
}否则{
Log.p(“btOpen NOK”);
}
Log.p(“btread-après侦听器:“+btread”);
}
@凌驾
公用无效读卡器断开连接(蓝牙设备蓝牙设备)
{
//Toast.makeText(com.codename1.impl.android.AndroidNativeUtil.getActivity(),“DISCONNECTED”,Toast.LENGTH\u SHORT.show();
EidReader.showDialog(“断开连接”);
}}
ScanBluetooth只是在表单开头调用的一种初始化方法:

public class EidReader extends Form implements HasLogger {

Container loggatt = new Container();
    private Bluetooth bt;
    private static Container devicesCnt;
    private Map devices = new HashMap();
    Form main = this;
    FtReaderNative frn;

    public EidReader(Form parent)
    {
        this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        Display dis = Display.getInstance();
        frn = (FtReaderNative)NativeLookup.create(FtReaderNative.class);
        if(dis.getPlatformName().compareTo("and")==0){
            LocationManager lm = LocationManager.getLocationManager();
        }
        bt = new Bluetooth();
        frn.scanBluetooth();
        //combo.setRenderer(new GenericListCellRenderer<>(new MultiButton(),new MultiButton()));
        this.add(new Button(new Command("enable bluetooth")
        {
            @Override
            public void actionPerformed(ActionEvent evt){

                try {
                    if (!bt.isEnabled()) {
                        bt.enable();
                    }
                    if (!bt.hasPermission()) {
                        bt.requestPermission();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }));
        this.add(new Button(new Command("initialize")
        {
            @Override
            public void actionPerformed(ActionEvent evt)
            {
                try {
                    bt.initialize(true, false, "bluetoothleplugin");
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }));

        Button bttest = new Button("DISPLAY READER");
        bttest.addActionListener(new ActionListener() 
        {
            public void actionPerformed(ActionEvent ev) 
            {
                DeleteUI();
                StringTokenizer st = new StringTokenizer(frn.infoDevices());
                while (st.hasMoreTokens()) {
                    MultiButton mb = new MultiButton(st.nextToken());
                    mb.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent ev) {
                            devicesCnt.add(new SpanLabel(frn.readerStatus( mb.getTextLine1())));
                        }});
                    devicesCnt.add(mb);
                }
            }
        });
        this.add(bttest);
        devicesCnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        devicesCnt.setScrollableY(true);
        this.add(devicesCnt);
        this.show();
}

    private void DeleteUI()
    {
        devicesCnt.removeAll();
        devicesCnt.revalidate();
    }
    @Override
    public String getLogName() 
    {
        // TODO Auto-generated method stub
        return null;
    }

    public static void showDialog(String txt)
    {
        //Display.getInstance().callSerially(()->
        //{
            devicesCnt.add(new SpanLabel(txt));
            devicesCnt.forceRevalidate();
        //});
    }

}
public类EidReader扩展表单实现HasLogger{
容器loggatt=新容器();
专用蓝牙;
专用静态容器设备CNT;
私有映射设备=新的HashMap();
Form main=此;
FTREderative frn;
公共读卡器(表格家长)
{
这个.setLayout(新的BoxLayout(BoxLayout.Y_轴));
Display dis=Display.getInstance();
frn=(FtReaderNative)NativeLookup.create(FtReaderNative.class);
if(dis.getPlatformName().compareTo(“and”)==0){
LocationManager lm=LocationManager.getLocationManager();
}
bt=新蓝牙();
frn.scanBluetooth();
//setRenderer(新的GenericListCellRenderer(新的多按钮(),新的多按钮());
添加(新按钮(新命令(“启用蓝牙”)
{
@凌驾
已执行的公共无效操作(操作事件evt){
试一试{
如果(!bt.isEnabled()){
bt.enable();
}
如果(!bt.hasPermission()){
bt.requestPermission();
}
}捕获(IOEX异常){
例如printStackTrace();
}
}
}));
添加(新按钮(新命令(“初始化”)
{
@凌驾
已执行的公共无效操作(操作事件evt)
{
试一试{
bt.initialize(真、假,“bluetoothleplugin”);
}捕获(IOEX异常){
例如printStackTrace();
}
}
}));
按钮bttest=新按钮(“显示阅读器”);
bttest.addActionListener(新的ActionListener()
{
已执行的公共无效操作(操作事件ev)
{
DeleteUI();
StringTokenizer st=新的StringTokenizer(frn.infoDevices());
而(st.hasMoreTokens()){
MultiButton mb=新的多按钮(st.nextToken());
mb.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件ev){
devicesCnt.add(新的SpanLabel(frn.readerStatus(mb.getTextLine1()));
}});
设备目录添加(mb);
}
}
});
添加(bttest);
devicesCnt=新容器(新的BoxLayout(BoxLayout.Y_轴));
设备Cnt.setScrollableY(真);
添加(devicesCnt);
this.show();
}
私有void DeleteUI()
{
devicesCnt.removeAll();
devicesCnt.revalidate();