Parcourir la source

1.添加service启动方法

master
wangwanlei il y a 11 mois
Parent
révision
ec15aea771

+ 17
- 2
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocketService.kt Voir le fichier

@@ -11,10 +11,18 @@ import android.os.Build
11 11
 import android.widget.Toast
12 12
 import com.xhly.corelib.Const
13 13
 import com.xhly.corelib.eventbus.UIEvent
14
+import com.xhly.corelib.network.RetrofitService
14 15
 import com.xhly.corelib.utils.LogShow
15 16
 import com.xhly.corelib.utils.SharedPreferencesUtils
17
+import com.xhly.manageapp.bean.LogdOperateBean
18
+import com.xhly.manageapp.network.LogService
16 19
 import com.xhly.websocket.service.LongConnService
17 20
 import com.xhly.websocket.utils.SocketPushUtils.dealPushMessage
21
+import kotlinx.coroutines.CoroutineScope
22
+import kotlinx.coroutines.GlobalScope
23
+import kotlinx.coroutines.MainScope
24
+import kotlinx.coroutines.cancel
25
+import kotlinx.coroutines.launch
18 26
 import org.greenrobot.eventbus.EventBus
19 27
 import org.greenrobot.eventbus.Subscribe
20 28
 import org.greenrobot.eventbus.ThreadMode
@@ -22,12 +30,14 @@ import org.greenrobot.eventbus.ThreadMode
22 30
 open class AppSocketService : LongConnService() {
23 31
     var CHANNEL_ID = "1"
24 32
     var CHANNEL_NAME = "通知"
33
+    var logService = RetrofitService.create<LogService>()
34
+    private val serviceScope = CoroutineScope(MainScope().coroutineContext)
25 35
 
26 36
     /*  private var csdkManager: CSDKManager? = null*/
27 37
     val spUtils by lazy { SharedPreferencesUtils.getInstance(this) }
28 38
 
29
-    companion object{
30
-         fun openWebSocket(context: Context) {
39
+    companion object {
40
+        fun openWebSocket(context: Context) {
31 41
             context.startService(Intent(context, AppSocketService::class.java))
32 42
         }
33 43
 
@@ -35,6 +45,7 @@ open class AppSocketService : LongConnService() {
35 45
             context.stopService(Intent(context, AppSocketService::class.java))
36 46
         }
37 47
     }
48
+
38 49
     override fun onCreate() {
39 50
         super.onCreate()
40 51
         EventBus.getDefault().register(this)
@@ -78,6 +89,9 @@ open class AppSocketService : LongConnService() {
78 89
             }
79 90
 
80 91
             "10086" -> {
92
+                serviceScope.launch {
93
+                    logService.postLogdoperateAdd(LogdOperateBean())
94
+                }
81 95
                 Toast.makeText(this, "违规操作,安装未知应用", Toast.LENGTH_LONG).show()
82 96
                 goMainActivity()
83 97
             }
@@ -104,6 +118,7 @@ open class AppSocketService : LongConnService() {
104 118
     override fun onDestroy() {
105 119
         super.onDestroy()
106 120
         EventBus.getDefault().unregister(this)
121
+        serviceScope.cancel()
107 122
         stopForeground(Service.STOP_FOREGROUND_REMOVE)
108 123
         /*  val intent=Intent(this,ManageService::class.java)
109 124
           startService(intent)*/

Chargement…
Annuler
Enregistrer