专栏名称: 复利大王
分享和推送Java/Android方向的技术和文章,让你成为这方面的大牛,让你每天都成长一点。同时,我们也会邀请BAT的大牛分享原创!
目录
相关文章推荐
鸿洋  ·  Android×AI ... ·  18 小时前  
复利大王  ·  西子电梯总裁跳楼 ·  19 小时前  
复利大王  ·  张艺谋最好的电影解禁了 ·  19 小时前  
复利大王  ·  有业主不想还房贷了? ·  昨天  
51好读  ›  专栏  ›  复利大王

Android黑科技之模拟点击的价值和实现,投广告者的福音!

复利大王  · 公众号  · android  · 2017-05-06 07:59

正文

请到「今天看啥」查看全文


MotionEvent upEvent = MotionEvent.obtain(downTime, downTime,            MotionEvent.ACTION_UP, x, y, 0 );    view.onTouchEvent(downEvent);    view.onTouchEvent(upEvent);    downEvent.recycle();    upEvent.recycle(); }

2)查看效果


Motionevent模拟点击

哎哟喂,这也行。我也装一个傻卖个萌什么的!现在都流行语音支付,如果小明捡到志玲姐姐的手机,我一定要试试她手机语音支付,对着志玲姐姐的手机娇滴滴的喊“萌萌站起来,加油,萌萌站起来~”。那为人兄,嘿~嘿嘿,呕吐袋已准备了在座椅右边!!

借着有志玲姐姐语音的高德地图导航,我们回到了三国赤壁。正好碰见孔明先生。“晚生小明,久仰诸葛先生大名!”,孔明见短发短袖短裤短腿短拖鞋的小明惊悚道:“何方妖怪?”,“噗~~

三.AccessibilityService实现模拟点击

1. 基本概念

AccessibilityService是Android提供有某些障碍手机人群使用的辅助服务,可以帮助用户实现点击屏幕等一些帮助。是一个很有爱的服务。
官方对这个功能介绍如下:

Many Android users have different abilities that require them to interact with their Android devices in different ways. These include users who have visual, physical or age-related limitations that prevent them from fully seeing or using a touchscreen, and users with hearing loss who may not be able to perceive audible information and alerts.

2. 实现原理

1)通过resource-id获取对应的View。

nodeInfo.findAccessibilityNodeInfosByViewId(resId);

2)或者通过带text属性的View。

nodeInfo.findAccessibilityNodeInfosByText(text);

3)执行AccessibleService的指定方法实现点击。

targetNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);

3. 实现过程

1)诸葛亮草船借箭

这个大家再熟悉不过了,舌战群儒后的草船借箭啦。

周瑜说“我这里只有船和水军,我没有‘贱’,孔明兄还是你来‘贱’吧!”,孔明君子之躯何贱之有啊,“短时间要我‘贱’,可以,你我通力合作可否?”。“行,只要你拿出‘贱’来,我同意,立下下军令状吧”周瑜得意挑衅。智比天高的诸葛亮想“我又不作‘贱’,还是找个‘贱’人来借一把吧!”

这样妙极了吧,曹操这么多‘贱’,草船使过来了,抖一抖‘贱’掉了一船,拿去!

①.舌战群儒后的合作击退曹操好比 AccessibleService 服务。
②.周瑜提供船和水军就是具体的 findAccessibilityNodeInfosByViewId(resId) findAccessibilityNodeInfosByText(text)
③.诸葛亮去敲鼓正是 performAction(AccessibilityNodeInfo.ACTION_CLICK) ;

2)如何获取resource-id或text
①.如何你是获取自己应用的 resource-id ,那就是布局xml定义的 @id/shuijun 或者 @+id/chuan
②.别人的软件,那就通过dump出view层级outline查找出resource-id或text。


dump页面分析

3)申明使用的服务要求
诸葛亮要申明我可以用兵用船。
①click_config.xml文件配置

xml version="1.0" encoding="utf-8"?><accessibility-service    xmlns:android="http://schemas.android.com/apk/res/android"    android:description="@string/click_auto"    android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged"    android:packageNames="com.youmi.android.addemo"    android:accessibilityFeedbackType="feedbackGeneric"    android:notificationTimeout="100"    android:accessibilityFlags=""    android:canRetrieveWindowContent="true"/>

②AndroidManifest.xml文件配置

<service    android:label="@string/app_name"    android:name="com.minggo.autoclick.ClickService"    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">    <intent-filter>         <action android:name="android.accessibilityservice.AccessibilityService"/>







请到「今天看啥」查看全文


推荐文章
复利大王  ·  西子电梯总裁跳楼
19 小时前
复利大王  ·  张艺谋最好的电影解禁了
19 小时前
复利大王  ·  有业主不想还房贷了?
昨天
摄影笔记  ·  摄友照片点评(构图不行)
8 年前
妙法佛音  ·  【法师开示】心的对接
8 年前
站长那点事  ·  如何让你的互联网情感营销打动人心?
8 年前
瞭望智库  ·  唐朝怎么就成了中国盛世的巅峰?
8 年前