瀏覽代碼

1.添加广播监听熄屏和亮屏处理设备提醒。

2.添加SN校验接口。
20241218TB223FC(测试jar包)
wangwanlei 11 月之前
父節點
當前提交
98616e2c3a

+ 19
- 0
app/src/main/java/com/xhly/manageapp/broadcastreceiver/ScreenReceiver.kt 查看文件

@@ -0,0 +1,19 @@
1
+package com.xhly.manageapp.broadcastreceiver
2
+
3
+import android.content.BroadcastReceiver
4
+import android.content.Context
5
+import android.content.Intent
6
+import com.xhly.corelib.Const
7
+import com.xhly.corelib.eventbus.UIEvent
8
+import com.xhly.corelib.utils.LogShow
9
+
10
+class ScreenReceiver: BroadcastReceiver() {
11
+    override fun onReceive(context: Context, intent: Intent) {
12
+        val action = intent.action
13
+        if (Intent.ACTION_SCREEN_ON==action){
14
+            UIEvent(Const.ACTION_SCREEN_ON).post()
15
+        }else if (Intent.ACTION_SCREEN_OFF==action){
16
+            UIEvent(Const.ACTION_SCREEN_OFF).post()
17
+        }
18
+    }
19
+}

+ 4
- 1
app/src/main/java/com/xhly/manageapp/network/UriAdress.kt 查看文件

@@ -139,5 +139,8 @@ object UriAdress {
139 139
      */
140 140
     const val AUTOAPP_DETAIL="/autoapp/detail_pad"
141 141
 
142
-
142
+    /**
143
+     * 校验sn,为true则退出
144
+     */
145
+    const val CHECK_SN="/ulogin/check_sn"
143 146
 }

+ 6
- 0
app/src/main/java/com/xhly/manageapp/ui/login/netservice/LoginService.kt 查看文件

@@ -86,4 +86,10 @@ interface LoginService {
86 86
      */
87 87
     @POST(UriAdress.AUTOAPP_DETAIL)
88 88
     suspend fun postAutoAppDetail(@Body map: HashMap<String, Any>):ResponseData<AutoAppBean>
89
+
90
+    /**
91
+     * 校验sn,true需要退出 false不需要退出
92
+     */
93
+    @POST(UriAdress.CHECK_SN)
94
+    suspend fun postCheckSn(@Body map: HashMap<String, Any>):ResponseData<Boolean>
89 95
 }

+ 41
- 3
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt 查看文件

@@ -72,6 +72,7 @@ import com.xhly.manageapp.bean.strategy.StrategyBean
72 72
 import com.xhly.manageapp.bean.user.UserBean
73 73
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
74 74
 import com.xhly.manageapp.broadcastreceiver.NetConnectReceiver
75
+import com.xhly.manageapp.broadcastreceiver.ScreenReceiver
75 76
 import com.xhly.manageapp.service.ManageAccessibilityService
76 77
 import com.xhly.manageapp.service.websocket.AppSocket
77 78
 import com.xhly.manageapp.ui.ManageActivity
@@ -98,6 +99,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
98 99
 
99 100
     private var mMyInstallReceiver: AppInstallReceiver? = null
100 101
     private var netConnectReceiver:NetConnectReceiver?=null
102
+    private var mScreenReceiver:ScreenReceiver?=null
101 103
     private var dataList: ArrayList<AppInfo> = arrayListOf()
102 104
     private var userBean: UserBean? = null
103 105
     private var timer: Timer? = null
@@ -120,6 +122,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
120 122
     private var canClickFlag=false
121 123
     //百度定位
122 124
     private var locationClient:LocationClient?=null
125
+
126
+    //上次提醒时长,用来设置是否重新设置提醒任务
127
+    private var lastTipsTimeLong=0
123 128
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
124 129
 
125 130
     @SuppressLint("CheckResult")
@@ -159,6 +164,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
159 164
         // checkAccessibility(this)
160 165
         registerAppInstallReceiver()
161 166
         registerNetConnectReceiver()
167
+        registerScreenReceiver()
162 168
         /*
163 169
          使用情况权限
164 170
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
@@ -914,8 +920,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
914 920
         }
915 921
     }
916 922
 
917
-    private fun startTimeTask(bean: SchoolDeviceSetBean) {
918
-        if (bean.remindDuration == 1 && bean.duration > 0) {
923
+    private fun startTimeTask(bean: SchoolDeviceSetBean,fromBroadcast:Boolean=false) {
924
+        //和上次时长不一致才使用,但是从广播调用时不用和上次时长对比
925
+        if (bean.remindDuration == 1 && bean.duration > 0&&(lastTipsTimeLong!=bean.duration||fromBroadcast)) {
919 926
             //如果设置的有时间则执行任务
920 927
             try {
921 928
                 timer?.cancel()
@@ -923,12 +930,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
923 930
             } catch (e: Exception) {
924 931
 
925 932
             }
933
+            lastTipsTimeLong=bean.duration
926 934
             timer?.let {
927 935
                 timer?.schedule(object : TimerTask() {
928 936
                     override fun run() {
929 937
                         Toast(getString(R.string.durationtips))
930 938
                     }
931
-                }, bean.duration * 60 * 1000L, bean.duration * 60 * 1000L)
939
+                }, bean.duration * 60 * 1000L, bean.duration* 60 * 1000L)
932 940
             }
933 941
         }
934 942
         //如果设置的有时间则取消所有任务
@@ -1133,6 +1141,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1133 1141
             Const.STARTSOCKET -> {
1134 1142
                 AppSocket.startSocket(this)
1135 1143
             }
1144
+
1145
+            Const.ACTION_SCREEN_ON->{
1146
+                StrategyUtils.getSchoolDeviceSetBean(this)?.let {
1147
+                    startTimeTask(it,true)
1148
+                }
1149
+            }
1150
+            Const.ACTION_SCREEN_OFF->{
1151
+                //取消定时任务
1152
+                if (timer != null) {
1153
+                    timer?.cancel()
1154
+                    timer = null
1155
+                }
1156
+                LogShow("关闭任务")
1157
+            }
1158
+            Const.ACCOUNTLOGINOUTSUCESS->{
1159
+                loginOutSucess()
1160
+            }
1136 1161
         }
1137 1162
     }
1138 1163
 
@@ -1268,6 +1293,16 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1268 1293
         registerReceiver(netConnectReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
1269 1294
     }
1270 1295
 
1296
+    /**
1297
+     * 熄屏注册监听
1298
+     */
1299
+    private fun registerScreenReceiver() {
1300
+        val filter = IntentFilter()
1301
+        filter.addAction(Intent.ACTION_SCREEN_ON)
1302
+        filter.addAction(Intent.ACTION_SCREEN_OFF)
1303
+        mScreenReceiver = ScreenReceiver()
1304
+        registerReceiver(mScreenReceiver, filter)
1305
+    }
1271 1306
 
1272 1307
     private fun showEditDialog() {
1273 1308
         if (accountDialog==null){
@@ -1372,6 +1407,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1372 1407
         netConnectReceiver?.let {
1373 1408
             unregisterReceiver(it)
1374 1409
         }
1410
+        mScreenReceiver?.let {
1411
+            unregisterReceiver(it)
1412
+        }
1375 1413
         LogShow("MainActivity被销毁")
1376 1414
     }
1377 1415
 

+ 8
- 0
app/src/main/java/com/xhly/manageapp/workmanager/TimingWorker.kt 查看文件

@@ -82,6 +82,14 @@ class TimingWorker(context: Context, workerParams: WorkerParameters) :
82 82
                 LogShow("没有位置问题"+e.toString())
83 83
             }
84 84
 */
85
+            userBean?.let {
86
+                val map=HashMap<String,Any>()
87
+                map["sn"]=ManageApplication.getDeviceInfo()?:""
88
+                val postCheckSn = loginService.postCheckSn(map)
89
+                if (postCheckSn.code==0&&postCheckSn.obj){
90
+                    UIEvent(Const.ACCOUNTLOGINOUTSUCESS).post()
91
+                }
92
+            }
85 93
             //创建socket
86 94
             userBean?.let {
87 95
                 ManageApplication.instance?.let {

+ 20
- 1
corelib/src/main/java/com/xhly/corelib/Const.kt 查看文件

@@ -1,5 +1,7 @@
1 1
 package com.xhly.corelib
2 2
 
3
+import android.content.Intent
4
+
3 5
 
4 6
 object Const {
5 7
     const val isDebug = false
@@ -9,6 +11,17 @@ object Const {
9 11
 
10 12
     //记录点击返回的次数,超过10次请求策略
11 13
     const val UPDATESTRATEGYNUM = 20
14
+
15
+    /**
16
+     * 标记熄屏
17
+     */
18
+    const val ACTION_SCREEN_OFF="ACTION_SCREEN_OFF"
19
+
20
+    /**
21
+     * 标记亮屏
22
+     */
23
+    const val ACTION_SCREEN_ON="ACTION_SCREEN_ON"
24
+
12 25
     /**
13 26
      * 当前应用包名
14 27
      */
@@ -79,10 +92,16 @@ object Const {
79 92
      */
80 93
      const val STARTSOCKET="STARTSOCKET"
81 94
     /**
82
-     * 标记推出1登录
95
+     * 标记推出登录
83 96
      */
84 97
     const val ACCOUNTLOGINOUT = "ACCOUNTLOGINOUT"
85 98
 
99
+    /**
100
+     * 标记直接退出,不调用接口
101
+     */
102
+    const val ACCOUNTLOGINOUTSUCESS = "ACCOUNTLOGINOUTSUCESS"
103
+
104
+
86 105
     /**
87 106
      * 调用安装app方法
88 107
      */

Loading…
取消
儲存