相关文章1Api比较详细
相关文章2
AccessibilityService
在res下新建xml目录
xml目录里建立配置accessibilityservice.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canRequestEnhancedWebAccessibility="true"
android:canRequestFilterKeyEvents="true"
android:canRequestTouchExplorationMode="true"
android:canRetrieveWindowContent="true"
android:description="@string/accessDescription"
android:notificationTimeout="100"
android:packageNames="com.tencent.mm"
android:settingsActivity=""
android:summary="" />
manifest.xml下
<service android:name=".accessibity.WeChatAuto"
android:label="@string/app_name"
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/第二个辅助功能配置方式的文件,存放在xml下"/>
</service>
往一个EditText里添加文字
public boolean chatSendEditInput(String text) {
if (TextUtils.isEmpty(text)) return false;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
List<AccessibilityNodeInfo> chatSendEditList = accNodeInfo.findAccessibilityNodeInfosByViewId(chatSendEditId);
AccessibilityNodeInfo chatSendEditNode = null;
if (null != chatSendEditList && chatSendEditList.size() != 0) {
chatSendEditNode = chatSendEditList.get(0);
}
if ("android.widget.EditText".equals(chatSendEditNode.getClassName())) {
Bundle arguments = new Bundle();
arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
text);
return chatSendEditNode.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT,
arguments);
}
return false;
}
手势模拟点击
相关文章https://www.jianshu.com/p/405f74ed000b
android7.0(N) 以上才可以
xml里配置属性:
android:canPerformGestures="true"
java方法:
public static void useGestureClick(AccessibilityNodeInfo info, AccessibilityService accessibilityService) {
if (info == null) {
return;
}
Rect rect = new Rect();
info.getBoundsInScreen(rect);
GestureDescription.Builder builder = new GestureDescription.Builder();
Path path = new Path();
path.moveTo(rect.centerX(), rect.centerY());
GestureDescription gestureDescription = builder
.addStroke(new GestureDescription.StrokeDescription(path, 100, 50))
.build();
accessibilityService.dispatchGesture(gestureDescription, new AccessibilityService.GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
super.onCompleted(gestureDescription);
}
}, null);
}
网友评论