1. Introduction
Other people's equipment and systems have no ability to modify the source code and can only seek other means. I saw someone on the Internet saying "no barriers", so I started to give it a try and found that it is feasible and much easier to use than adb;
Two, use
New class MyAccessibilityService
public class MyAccessibilityService extends AccessibilityService {
String TAG = "AliAccessibilityService" ;
@Override
public void onAccessibilityEvent ( AccessibilityEvent event) {
if ( event. getPackageName ( ) . equals ( "com.android.systemui" ) && event. getClassName ( ) . equals ( "android.app.Dialog" ) && event. getText ( ) . get ( 0 ) . equals ( getAppName ( getApplicationContext ( ) ) ) ) {
AccessibilityNodeInfo nodeInfo = event. getSource ( ) ;
for ( int i = 0 ; i < nodeInfo. getChildCount ( ) ; i++ ) {
if ( nodeInfo. getChild ( i) . getClassName ( ) . equals ( "android.widget.CheckBox" ) ) {
Log. d ( TAG, "onAccessibilityEvent: " + nodeInfo. getChild ( i) . getClassName ( ) + ": " + nodeInfo. getChild ( i) . getText ( ) ) ;
nodeInfo. getChild ( i) . performAction ( AccessibilityNodeInfo. ACTION_CLICK) ;
}
}
for ( int i = 0 ; i < nodeInfo. getChildCount ( ) ; i++ ) {
if ( nodeInfo. getChild ( i) . getClassName ( ) . equals ( "android.widget.ScrollView" ) ) {
for ( int j = 0 ; j < nodeInfo. getChild ( i) . getChildCount ( ) ; j++ ) {
if ( nodeInfo. getChild ( i) . getChild ( j) . getClassName ( ) . equals ( "android.widget.Button" ) && nodeInfo. getChild ( i) . getChild ( j) . getText ( ) . equals ( "确定" ) ) {
Log. d ( TAG, "onAccessibilityEvent: " + nodeInfo. getChild ( i) . getChild ( j) . getClassName ( ) + ": " + nodeInfo. getChild ( i) . getChild ( j) . getText ( ) ) ;
nodeInfo. getChild ( i) . getChild ( j) . performAction ( AccessibilityNodeInfo. ACTION_CLICK) ;
return ;
}
}
}
}
}
}
@Override
public void onInterrupt ( ) {
Log. d ( TAG, "onInterrupt" ) ;
}
public static String getAppName ( Context context) {
try {
PackageManager packageManager = context. getPackageManager ( ) ;
PackageInfo packageInfo = packageManager. getPackageInfo (
context. getPackageName ( ) , 0 ) ;
int labelRes = packageInfo. applicationInfo. labelRes;
return context. getResources ( ) . getString ( labelRes) ;
} catch ( Exception e) {
e. printStackTrace ( ) ;
}
return null;
}
}
Declare service, and create xml under res, and then create accessibility_service file under xml. You can search for specific parameter descriptions, but I won’t repeat them here.
< manifest xmlns: android= "http://schemas.android.com/apk/res/android"
package = "com.example.ysy200506_1sw" >
. . . . . .
< application
. . . . . .
< service
android: name= ".MyAccessibilityService"
android: label= "USB读取自动授权"
android: permission= "android.permission.BIND_ACCESSIBILITY_SERVICE" >
< intent- filter>
< action android: name= "android.accessibilityservice.AccessibilityService" / >
< / intent- filter>
< meta- data
android: name= "android.accessibilityservice"
android: resource= "@xml/accessibility_service" / >
< / service>
< / application>
< / manifest>
< accessibility- service
xmlns: android= "http://schemas.android.com/apk/res/android"
android: accessibilityEventTypes= "typeWindowStateChanged"
android: accessibilityFeedbackType= "feedbackGeneric"
android: canRetrieveWindowContent= "true"
android: description= "@string/app_name"
android: notificationTimeout= "100" / >
default setting
After the code is written, you need to manually turn on the accessibility service of the application, which can be set by code jump, or directly set at the factory
Precautions
Once the program crashes, the accessibility service will fail, and the system needs to be restarted to recover
Once the program is reinstalled or upgraded, the accessibility will also be invalid, and you need to restart it manually