欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

AIDE实现无障碍点击控件

时间:2023-06-16

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

wechatlog_service_config.xml

<?xml version="1.0" encoding="utf-8"?>

WeChatLogService.java

package com.mycompany.myapp;import android.accessibilityservice.AccessibilityService;import android.content.Intent;import android.graphics.Rect;import android.os.Environment;import android.text.TextUtils;import android.util.Log;import android.view.accessibility.AccessibilityEvent;import android.view.accessibility.AccessibilityNodeInfo;import android.widget.Toast;import java.util.List;import android.accessibilityservice.*;import android.graphics.*;import androidx.annotation.*;import android.os.*;import android.app.*;import android.content.*;import android.content.pm.*;public class WeChatLogService extends AccessibilityService{private int AA; public static WeChatLogService mService; @Override public void onAccessibilityEvent(AccessibilityEvent event){ int eventType = event.getEventType();AccessibilityNodeInfo rootNodeInfo = getRootInActiveWindow();List nodes1=rootNodeInfo.findAccessibilityNodeInfosByViewId("com.mycompany.myapp:id/main_button1");//Log.e("控件信息", AA + " " + nodes1.toString());if (nodes1.size() != 0){nodes1.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);}} @Override public void onInterrupt(){ Toast.makeText(this, "我快被终结了啊-----", Toast.LENGTH_SHORT).show(); } @Override protected void onServiceConnected(){ Toast.makeText(this, "服务已开启", Toast.LENGTH_SHORT).show(); super.onServiceConnected();weixin(); } @Override public boolean onUnbind(Intent intent){ Toast.makeText(this, "服务已被关闭", Toast.LENGTH_SHORT).show(); return super.onUnbind(intent); }public static boolean isStart() { return mService != null; }private void weixin(){PackageManager packageManager = getPackageManager();Intent intent = new Intent(); //跳转到下一页5 APP界面intent = packageManager.getLaunchIntentForPackage("com.tencent.mm");startActivity(intent);}}

activity_main.xml

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。