Browse Source

1.添加无障碍服务ManageAccessibilityService

master
wangwanlei 10 months ago
parent
commit
4c662ed3b0

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

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

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

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 View File

25
 import com.xhly.corelib.utils.AppUtils
25
 import com.xhly.corelib.utils.AppUtils
26
 import com.xhly.corelib.utils.LogShow
26
 import com.xhly.corelib.utils.LogShow
27
 import com.xhly.manageapp.AppAdapter
27
 import com.xhly.manageapp.AppAdapter
28
-import com.xhly.manageapp.ManageApplication
29
 import com.xhly.manageapp.R
28
 import com.xhly.manageapp.R
30
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
29
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
31
 import com.xhly.manageapp.databinding.ActivityMainBinding
30
 import com.xhly.manageapp.databinding.ActivityMainBinding
32
-import com.xhly.manageapp.service.TestService
31
+import com.xhly.manageapp.service.ManageAccessibilityService
33
 import com.xhly.manageapp.ui.login.activity.LoginActivity
32
 import com.xhly.manageapp.ui.login.activity.LoginActivity
34
 import com.xhly.websocket.utils.WebSocketUtils
33
 import com.xhly.websocket.utils.WebSocketUtils
35
 import java.util.Calendar
34
 import java.util.Calendar
225
 
224
 
226
     fun checkAccessibility(context: Context): Boolean {
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
             context.startActivity(
229
             context.startActivity(
231
                 Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
230
                 Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)

Loading…
Cancel
Save