|
@@ -1,10 +1,11 @@
|
1
|
|
-package com.xhly.websocket.service
|
|
1
|
+package com.xhly.manageapp.service.websocket
|
2
|
2
|
|
3
|
3
|
import android.app.Notification
|
4
|
4
|
import android.app.NotificationChannel
|
5
|
5
|
import android.app.NotificationManager
|
6
|
6
|
import android.app.Service
|
7
|
7
|
import android.content.ComponentName
|
|
8
|
+import android.content.Context
|
8
|
9
|
import android.content.Intent
|
9
|
10
|
import android.os.Build
|
10
|
11
|
import android.widget.Toast
|
|
@@ -12,21 +13,33 @@ import com.xhly.corelib.Const
|
12
|
13
|
import com.xhly.corelib.eventbus.UIEvent
|
13
|
14
|
import com.xhly.corelib.utils.LogShow
|
14
|
15
|
import com.xhly.corelib.utils.SharedPreferencesUtils
|
|
16
|
+import com.xhly.websocket.service.LongConnService
|
15
|
17
|
import com.xhly.websocket.utils.SocketPushUtils.dealPushMessage
|
16
|
18
|
import org.greenrobot.eventbus.EventBus
|
17
|
19
|
import org.greenrobot.eventbus.Subscribe
|
18
|
20
|
import org.greenrobot.eventbus.ThreadMode
|
19
|
21
|
|
20
|
|
-open class SocketService : LongConnService() {
|
|
22
|
+open class AppSocketService : LongConnService() {
|
21
|
23
|
var CHANNEL_ID = "1"
|
22
|
24
|
var CHANNEL_NAME = "通知"
|
23
|
|
- /* private var csdkManager: CSDKManager? = null*/
|
|
25
|
+
|
|
26
|
+ /* private var csdkManager: CSDKManager? = null*/
|
24
|
27
|
val spUtils by lazy { SharedPreferencesUtils.getInstance(this) }
|
|
28
|
+
|
|
29
|
+ companion object{
|
|
30
|
+ fun openWebSocket(context: Context) {
|
|
31
|
+ context.startService(Intent(context, AppSocketService::class.java))
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ fun closeWebSocket(context: Context) {
|
|
35
|
+ context.stopService(Intent(context, AppSocketService::class.java))
|
|
36
|
+ }
|
|
37
|
+ }
|
25
|
38
|
override fun onCreate() {
|
26
|
39
|
super.onCreate()
|
27
|
40
|
EventBus.getDefault().register(this)
|
28
|
41
|
connectUrl = "wss://api.stsotc.com/api/ws"
|
29
|
|
- /* csdkManager = CSDKManager(this)*/
|
|
42
|
+ /* csdkManager = CSDKManager(this)*/
|
30
|
43
|
/* startNotification()*/
|
31
|
44
|
}
|
32
|
45
|
|
|
@@ -42,9 +55,9 @@ open class SocketService : LongConnService() {
|
42
|
55
|
|
43
|
56
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
44
|
57
|
fun onUiEvent(uiEvent: UIEvent) {
|
45
|
|
- /* if (csdkManager == null) {
|
46
|
|
- csdkManager = CSDKManager(this)
|
47
|
|
- }*/
|
|
58
|
+ /* if (csdkManager == null) {
|
|
59
|
+ csdkManager = CSDKManager(this)
|
|
60
|
+ }*/
|
48
|
61
|
when (uiEvent.event) {
|
49
|
62
|
Const.CODE2001.toString() -> {
|
50
|
63
|
Toast.makeText(this, "这就是新消息", Toast.LENGTH_LONG).show()
|