Ver código fonte

1.在定时任务中定时调用socket,以便在销毁后重启

20241218TB223FC(测试jar包)
wangwanlei 9 meses atrás
pai
commit
097ea8dd8f

+ 1
- 1
app/src/main/java/com/xhly/manageapp/ManageApplication.kt Ver arquivo

@@ -500,7 +500,7 @@ class ManageApplication : MultiDexApplication() {
500 500
         super.onCreate()
501 501
         instance = this
502 502
         Toaster.init(this)
503
-        apppSocket = AppSocket()
503
+        apppSocket = AppSocket
504 504
         apppSocket?.startSocket(this)
505 505
         if (ModelNameUtils.IS_LianxX505f()) {
506 506
             //是505f则执行

+ 2
- 20
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocket.kt Ver arquivo

@@ -37,23 +37,11 @@ import org.greenrobot.eventbus.ThreadMode
37 37
 import java.io.File
38 38
 import java.util.UUID
39 39
 
40
-class AppSocket : SocketClient() {
41
-    var logService = RetrofitService.create<LogService>()
42
-    private val serviceScope = CoroutineScope(MainScope().coroutineContext)
43
-
44
-
45
-    val spUtils by lazy { SharedPreferencesUtils.getInstance(context) }
46
-
47
-    companion object {
48
-        //标记上次打开的包名,当连续打开同一包名时,不认为打开多次
49
-        var lastPkgName = ""
50
-    }
40
+object AppSocket : SocketClient() {
51 41
 
52 42
     override fun startSocket(context: Context?) {
53 43
         connectUrl = Const.WSURL
54
-        /* startNotification()*/
55 44
         LogShow("已经创建")
56
-        //downLoadFile("")
57 45
         super.startSocket(context)
58 46
     }
59 47
 
@@ -86,12 +74,6 @@ class AppSocket : SocketClient() {
86 74
 
87 75
     override fun onDestroy() {
88 76
         super.onDestroy()
89
-        serviceScope.cancel()
90
-        /* stopForeground(Service.STOP_FOREGROUND_REMOVE)*/
91
-        val intent = Intent()
92
-        intent.setPackage("com.xhly.manageapp")
93
-        intent.setAction("test")
94
-        context.sendBroadcast(intent)
95
-        LogShow("Service被销毁")
77
+        LogShow("Socket被销毁")
96 78
     }
97 79
 }

+ 2
- 2
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt Ver arquivo

@@ -578,12 +578,12 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
578 578
 
579 579
             Const.LOGAPPSTART -> {
580 580
                 val message = uiEvent.message
581
-                if (AppSocket.lastPkgName == message) {
581
+                if (Const.LASTPKGNAME == message) {
582 582
                     return
583 583
                 }
584 584
                 val filter = dataList.filter { it.packageName == message }
585 585
                 if (filter.isNotEmpty()) {
586
-                    AppSocket.lastPkgName = message
586
+                    Const.LASTPKGNAME = message
587 587
                     val data = LogdOperateBean()
588 588
                     ManageApplication.getDeviceInfo()?.let {
589 589
                         data.sn = it

+ 5
- 0
app/src/main/java/com/xhly/manageapp/workmanager/TimingWorker.kt Ver arquivo

@@ -18,6 +18,7 @@ import com.xhly.manageapp.bean.log.LogAppStartBean
18 18
 import com.xhly.manageapp.bean.log.PadLocationBean
19 19
 import com.xhly.manageapp.bean.user.UserBean
20 20
 import com.xhly.manageapp.network.log.LogService
21
+import com.xhly.manageapp.service.websocket.AppSocket
21 22
 import kotlinx.coroutines.CoroutineScope
22 23
 import kotlinx.coroutines.MainScope
23 24
 import kotlinx.coroutines.cancel
@@ -74,6 +75,10 @@ class TimingWorker(context: Context, workerParams: WorkerParameters) :
74 75
             }catch (e:Exception){
75 76
                 LogShow("没有位置问题"+e.toString())
76 77
             }
78
+            //创建socket
79
+            ManageApplication.instance?.let {
80
+                AppSocket.startSocket(it)
81
+            }
77 82
         }
78 83
         return result
79 84
     }

+ 3
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt Ver arquivo

@@ -16,6 +16,9 @@ object Const {
16 16
     //班级id
17 17
     var CLASSID = 0L
18 18
 
19
+    //标记上次打开的包名,当连续打开同一包名时,不认为打开多次
20
+    var LASTPKGNAME = ""
21
+
19 22
     //接口地址
20 23
     const val URL1: String = "https://mcapitest.xhkjedu.com/"
21 24
 

+ 1
- 4
websocket/src/main/java/com/xhly/websocket/service/SocketClient.java Ver arquivo

@@ -154,10 +154,7 @@ public abstract class SocketClient {
154 154
      * 连接长链接
155 155
      */
156 156
     private synchronized void startConnect() {
157
-        if (TextUtils.isEmpty("用户ID")) {
158
-            setStatus(WsStatus.DISCONNECT);
159
-            return;
160
-        }
157
+
161 158
         if (!NetworkUtils.isAvailable(context)) {
162 159
             Toast.makeText(context, "网络不可用", Toast.LENGTH_SHORT);
163 160
             return;

Carregando…
Cancelar
Salvar