本文主要是介绍AccessibilityService 手机联通营业厅自动签到器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.手机联通营业厅自动签到器
2. Demo下载
https://github.com/sufadi/AccessibilityServiceMonitor
3. 实现思路
3.1 打开联通界面
public static void startLiangTongUI(Context mContext) {Intent intent = new Intent();intent.setPackage("com.sinovatech.unicom.ui");intent.setClassName("com.sinovatech.unicom.ui", "com.sinovatech.unicom.basic.ui.MainActivity");mContext.startActivity(intent);}
3.2 点击主界面的联通界面的签到按钮
实现思路,根据resource id 进行控件的点选,即findAccessibilityNodeInfosByViewId
/*** 跳转到签到界面* @param nodeInfo* @param packageName* @param className*/public static void startLiangTongQianDaoUI(AccessibilityNodeInfo nodeInfo, String packageName, String className) {if (nodeInfo == null) {return;}CommonUtil.clickBtnByResId(nodeInfo, "com.sinovatech.unicom.ui:id/home_header_long_qiandao_image");}public static void clickBtnByResId(AccessibilityNodeInfo nodeInfo, String id) {if (nodeInfo != null) {// 该界面下所有 ViewId 节点List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByViewId(id);for (AccessibilityNodeInfo item : list) {if (item.isClickable()) {item.performAction(AccessibilityNodeInfo.ACTION_CLICK);Log.d(Config.TAG, "clickBtnByResId = " + item.toString());break;}}}}
3.3 点击WebView的联通界面的签到按钮
这里的思路是先找到 “android.webkit.WebView”,然后在 webView 中进一步找到签到按钮,对应上面图示。
/*** 点击自动签到** @param nodeInfo* @param packageName* @param className*/public static void policy(AccessibilityNodeInfo nodeInfo, String packageName, String className) {if (nodeInfo == null) {return;}if ("com.sinovatech.unicom.ui".equals(packageName)) {for (int i = 0; i < nodeInfo.getChildCount(); i++) {AccessibilityNodeInfo child = nodeInfo.getChild(i);if ("android.webkit.WebView".equals(child.getClassName())) {Log.d(Config.TAG, "nodeInfo = " + nodeInfo.toString());findEveryViewNode(child);break;}}}}public static void findEveryViewNode(AccessibilityNodeInfo node) {if (null != node && node.getChildCount() > 0) {for (int i = 0; i < node.getChildCount(); i++) {AccessibilityNodeInfo child = node.getChild(i);// 有时 child 为空if (child == null) {continue;}String className = child.getViewIdResourceName();if ("qd_xq".equals(className)) {Log.d(Config.TAG, "Button 的节点数据 text = " + child.getText() + ", descript = " + child.getContentDescription() + ", className = " + child.getClassName() + ", resId = " + child.getViewIdResourceName());boolean isClickable = child.isClickable();if ( isClickable) {child.performAction(AccessibilityNodeInfo.ACTION_CLICK);Log.d(Config.TAG, "联通签到 成功点击");}}// 递归调用findEveryViewNode(child);}}}
具体日子打印如下
2018-08-28 17:25:04.541 28655-28655/? D/suhuazhi: Button 的节点数据 text = , descript = null, className = android.view.View, resId = qd_xq
2018-08-28 17:25:04.543 28655-28655/? D/suhuazhi: 联通签到 成功点击
这篇关于AccessibilityService 手机联通营业厅自动签到器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!