From aecc5aa11fd2cbdea193db53adfc7c7920f43b26 Mon Sep 17 00:00:00 2001
From: whyclj <1525436766@qq.com>
Date: 星期一, 21 十月 2019 13:27:32 +0800
Subject: [PATCH] 修复bug

---
 platforms/android/app/src/main/java/com/service/MyInteractionService.java |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/platforms/android/app/src/main/java/com/service/MyInteractionService.java b/platforms/android/app/src/main/java/com/service/MyInteractionService.java
index cca3a3d..81b655e 100644
--- a/platforms/android/app/src/main/java/com/service/MyInteractionService.java
+++ b/platforms/android/app/src/main/java/com/service/MyInteractionService.java
@@ -29,11 +29,12 @@
     private DeviceState deviceState = null;
     private FTPFileUtil ftpFileUtil = null;
 
+    private boolean isRunning = false;
 
     public MyInteractionService(String serverip, JsInterface jsInterface){
         sockethread = new MySocketClientThread(serverip);
         ftpFileUtil = new FTPFileUtil();
-        sockethread.start();
+
         this.serverip = serverip;
 
         this.mSocketHandle = new Handler(){
@@ -44,9 +45,9 @@
                     //鑾峰彇娴嬭瘯鍙傛暟
                     jsInterface.SendCallDataToJS("getTestParam",model);
                 }else if(FBS_ComBase.CMD_HEARTBEAT == model.cmd){
-                    //蹇冭烦鍖呰繑鍥�
+                    //蹇冭烦鍖呰繑
                     deviceState = (DeviceState)model.data;
-                    jsInterface.SendCallDataToJS("getNowWorkBatt",model);
+                    //jsInterface.SendCallDataToJS("getNowWorkBatt",model);
                 }else if(FBS_ComBase.CMD_CREATENEWBATT == model.cmd){
                     //鏂板缓鐢垫睜缁�
                     //model.data = deviceState;
@@ -98,24 +99,26 @@
             }
         };
 
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                while (true){
+                    try {
+                        if(isRunning){
+                            //鍙戦�佸績璺冲寘缁欒澶�
+                            sendMessageToSocketClient(mSocketHandle, FBS_ComBase.CMD_HEARTBEAT, "");
+                            Log.e(TAG, "run: ######################################" );
+                        }
+                        //handler.removeCallbacks(runnable);
+                        Thread.sleep(4000);
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }).start();
 
-//        new Thread(new Runnable() {
-//            @Override
-//            public void run() {
-//                while (true){
-//                    try {
-//                        //鍙戦�佸績璺冲寘缁欒澶�
-//                        sendMessageToSocketClient(mSocketHandle, FBS_ComBase.CMD_HEARTBEAT, "");
-//                        Log.e(TAG, "run: ######################################" );
-//                        //handler.removeCallbacks(runnable);
-//                        Thread.sleep(1000);
-//                    } catch (InterruptedException e) {
-//                        e.printStackTrace();
-//                    }
-//                }
-//            }
-//        }).start();
-
+        this.sockethread.start();
     }
 
     //璁剧疆璁惧ip
@@ -123,7 +126,9 @@
         boolean flag = true;
         this.serverip = serverip;
         this.ftpFileUtil.server_ip = serverip;
+
         flag = sockethread.setUpDeviceIp(serverip);
+        isRunning = true;
         return flag;
     }
 

--
Gitblit v1.9.1