📄 bluetoothclient.java
字号:
//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|64-getter|0|64-preInit /** * Returns an initiliazed instance of exitCommand1 component. * @return the initialized component instance */ public Command getExitCommand1() { if (exitCommand1 == null) {//GEN-END:|64-getter|0|64-preInit // write pre-init user code here exitCommand1 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|64-getter|1|64-postInit // write post-init user code here }//GEN-BEGIN:|64-getter|2| return exitCommand1; } //</editor-fold>//GEN-END:|64-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand2 ">//GEN-BEGIN:|69-getter|0|69-preInit /** * Returns an initiliazed instance of exitCommand2 component. * @return the initialized component instance */ public Command getExitCommand2() { if (exitCommand2 == null) {//GEN-END:|69-getter|0|69-preInit // write pre-init user code here exitCommand2 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|69-getter|1|69-postInit // write post-init user code here }//GEN-BEGIN:|69-getter|2| return exitCommand2; } //</editor-fold>//GEN-END:|69-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|71-getter|0|71-preInit /** * Returns an initiliazed instance of backCommand3 component. * @return the initialized component instance */ public Command getBackCommand3() { if (backCommand3 == null) {//GEN-END:|71-getter|0|71-preInit // write pre-init user code here backCommand3 = new Command("BackToMainMenu", Command.BACK, 0);//GEN-LINE:|71-getter|1|71-postInit // write post-init user code here }//GEN-BEGIN:|71-getter|2| return backCommand3; } //</editor-fold>//GEN-END:|71-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: screenCommand3 ">//GEN-BEGIN:|74-getter|0|74-preInit /** * Returns an initiliazed instance of screenCommand3 component. * @return the initialized component instance */ public Command getScreenCommand3() { if (screenCommand3 == null) {//GEN-END:|74-getter|0|74-preInit // write pre-init user code here screenCommand3 = new Command("Log", Command.SCREEN, 0);//GEN-LINE:|74-getter|1|74-postInit // write post-init user code here }//GEN-BEGIN:|74-getter|2| return screenCommand3; } //</editor-fold>//GEN-END:|74-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand3 ">//GEN-BEGIN:|77-getter|0|77-preInit /** * Returns an initiliazed instance of exitCommand3 component. * @return the initialized component instance */ public Command getExitCommand3() { if (exitCommand3 == null) {//GEN-END:|77-getter|0|77-preInit // write pre-init user code here exitCommand3 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|77-getter|1|77-postInit // write post-init user code here }//GEN-BEGIN:|77-getter|2| return exitCommand3; } //</editor-fold>//GEN-END:|77-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: deviceAlert ">//GEN-BEGIN:|79-getter|0|79-preInit /** * Returns an initiliazed instance of deviceAlert component. * @return the initialized component instance */ public Alert getDeviceAlert() { if (deviceAlert == null) {//GEN-END:|79-getter|0|79-preInit // write pre-init user code here Gauge inqGau = new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING); deviceAlert = new Alert("Searching", "Searching Devices..", null, null);//GEN-BEGIN:|79-getter|1|79-postInit deviceAlert.setTimeout(Alert.FOREVER);//GEN-END:|79-getter|1|79-postInit // write post-init user code here deviceAlert.setIndicator(inqGau); }//GEN-BEGIN:|79-getter|2| return deviceAlert; } //</editor-fold>//GEN-END:|79-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: waitBrowseAlert ">//GEN-BEGIN:|81-getter|0|81-preInit /** * Returns an initiliazed instance of waitBrowseAlert component. * @return the initialized component instance */ public Alert getWaitBrowseAlert() { if (waitBrowseAlert == null) {//GEN-END:|81-getter|0|81-preInit // write pre-init user code here Gauge inqGau = new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING); waitBrowseAlert = new Alert("Wait for Browsing ", "Wait to complete Browsing...", null, null);//GEN-BEGIN:|81-getter|1|81-postInit waitBrowseAlert.setTimeout(Alert.FOREVER);//GEN-END:|81-getter|1|81-postInit // write post-init user code here waitBrowseAlert.setIndicator(inqGau); }//GEN-BEGIN:|81-getter|2| return waitBrowseAlert; } //</editor-fold>//GEN-END:|81-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: waitSynchronizeAlert ">//GEN-BEGIN:|84-getter|0|84-preInit /** * Returns an initiliazed instance of waitSynchronizeAlert component. * @return the initialized component instance */ public Alert getWaitSynchronizeAlert() { if (waitSynchronizeAlert == null) {//GEN-END:|84-getter|0|84-preInit // write pre-init user code here Gauge inqGau = new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING); waitSynchronizeAlert = new Alert("Wait for Synchronizing", "Synchronizing...", null, null);//GEN-BEGIN:|84-getter|1|84-postInit waitSynchronizeAlert.setTimeout(Alert.FOREVER);//GEN-END:|84-getter|1|84-postInit // write post-init user code here waitSynchronizeAlert.setIndicator(inqGau); }//GEN-BEGIN:|84-getter|2| return waitSynchronizeAlert; } //</editor-fold>//GEN-END:|84-getter|2| public Display getDisplay () { return Display.getDisplay(this); } /* MiDlet Default Methods... */ public void exitMIDlet() { switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } public void startApp() { if (midletPaused) { resumeMIDlet (); } else { initialize (); startMIDlet (); } midletPaused = false; } public void pauseApp() { midletPaused = true; } public void destroyApp(boolean unconditional) { } /* DiscoveryListener methods for Events... */ public void deviceDiscovered(RemoteDevice btDevice, DeviceClass arg1) { try{ log("A device discovered (" + getDeviceStr(btDevice) + ")"); deviceListVec.addElement(btDevice); }catch(Exception e){ log(e); } } public void servicesDiscovered(int transId, ServiceRecord[] records) { try { log("Service discovered."); for (int i = 0; i < records.length; i++) { ServiceRecord rec = records[i]; String url = rec.getConnectionURL(connectionOptions, false); establishConnection(url); log("establish connection..."); } log("Discoverd Services...:"+records.length); } catch (Exception e) { log(e); } } public void serviceSearchCompleted(int arg0, int arg1) { } public void inquiryCompleted(int arg0) { try { log("Inquiry compeleted. Please select device from combo box."); makeDeviceSelectionGUI(); } catch (Exception e) { log(e); } } /* device search and service search method...*/ private void startServiceSearch(RemoteDevice device) { try { UUID uuids[] = new UUID[] { uuid }; getAgent().searchServices(null, uuids, device, this); } catch (Exception e) { log(e); } } private void establishConnection(String URL){ stream = null; try { // Thread.currentThread().sleep(5000); stream = (StreamConnection) Connector.open(URL); //log("Creating op stream"); // Thread.currentThread().sleep(5000); out = stream.openOutputStream(); in = stream.openInputStream(); if(UserAction.equals("Synchronize")){ log("Synchronize thread called..."); contactSynchroninzing = new Thread(contactSynchronize); contactSynchroninzing.start(); }else if(UserAction.equals("Restore")){ log("Restore Thread Called..."); contactRestoring = new Thread(contactRestore); contactRestoring.start(); } UserAction=""; //log("Start echo loop."); }catch(Exception e){ } } private void startDeviceInquiry() { try { log("Start inquiry method - this will take few seconds..."); if(!deviceListVec.isEmpty()){ deviceListVec.removeAllElements(); deviceList.deleteAll(); } DiscoveryAgent agent = getAgent(); agent.startInquiry(inquiryMode, this); } catch (Exception e) { log(e); } } /* GUI methods for create */ private void makeDeviceSelectionGUI() { try { for (int i = 0; i < deviceListVec.size(); i++){ getDeviceList().append(getDeviceStr((RemoteDevice) deviceListVec.elementAt(i)), null); } switchDisplayable(null,getDeviceList()); }catch(Exception e){ log(e); } } /* BlueToothDevice Information Methods. */ private DiscoveryAgent getAgent() { try { return LocalDevice.getLocalDevice().getDiscoveryAgent(); } catch (BluetoothStateException e) { log(e); return null; } } private String getDeviceStr(RemoteDevice btDevice) { return getFriendlyName(btDevice) + " - 0x" + btDevice.getBluetoothAddress(); } private String getFriendlyName(RemoteDevice btDevice) { try { return btDevice.getFriendlyName(false); } catch (IOException e) { log(e); return "no name available";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -