Sfoglia il codice sorgente

1.添加无障碍服务ManageAccessibilityService

master
wangwanlei 10 mesi fa
parent
commit
4c662ed3b0

+ 1
- 1
app/src/main/AndroidManifest.xml Vedi File

@@ -107,7 +107,7 @@
107 107
              </receiver>-->
108 108
 
109 109
         <service
110
-            android:name=".service.TestService"
110
+            android:name=".service.ManageAccessibilityService"
111 111
             android:exported="true"
112 112
             android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
113 113
             <intent-filter>

+ 27
- 0
app/src/main/java/com/xhly/manageapp/service/ManageAccessibilityService.kt Vedi File

@@ -0,0 +1,27 @@
1
+package com.xhly.manageapp.service
2
+
3
+import android.accessibilityservice.AccessibilityService
4
+import android.view.accessibility.AccessibilityEvent
5
+import com.xhly.corelib.utils.LogShow
6
+
7
+class ManageAccessibilityService : AccessibilityService() {
8
+    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
9
+       event?.let {
10
+           if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == it.eventType) {
11
+               LogShow(it.packageName.toString() +"|||" + it.className.toString())
12
+               if (it.className.toString().equals("com.example.mytestxf.MainActivity")){
13
+                   performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
14
+               }
15
+           }
16
+       }
17
+    }
18
+
19
+    override fun onInterrupt() {
20
+
21
+    }
22
+
23
+    override fun onDestroy() {
24
+        super.onDestroy()
25
+        LogShow("我被销毁")
26
+    }
27
+}

+ 2
- 3
app/src/main/java/com/xhly/manageapp/ui/MainActivity.kt Vedi File

@@ -25,11 +25,10 @@ import com.xhly.corelib.eventbus.UIEvent
25 25
 import com.xhly.corelib.utils.AppUtils
26 26
 import com.xhly.corelib.utils.LogShow
27 27
 import com.xhly.manageapp.AppAdapter
28
-import com.xhly.manageapp.ManageApplication
29 28
 import com.xhly.manageapp.R
30 29
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
31 30
 import com.xhly.manageapp.databinding.ActivityMainBinding
32
-import com.xhly.manageapp.service.TestService
31
+import com.xhly.manageapp.service.ManageAccessibilityService
33 32
 import com.xhly.manageapp.ui.login.activity.LoginActivity
34 33
 import com.xhly.websocket.utils.WebSocketUtils
35 34
 import java.util.Calendar
@@ -225,7 +224,7 @@ class MainActivity : BaseActivity<CommonBaseViewModel, ActivityMainBinding>() {
225 224
 
226 225
     fun checkAccessibility(context: Context): Boolean {
227 226
         // 判断辅助功能是否开启
228
-        if (!isServiceON(this, TestService::class.java.name)) {
227
+        if (!isServiceON(this, ManageAccessibilityService::class.java.name)) {
229 228
             // 引导至辅助功能设置页面
230 229
             context.startActivity(
231 230
                 Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)

Loading…
Annulla
Salva