实现微信自动向附近的人打招呼,实现收到指定账户推送文章时自动进入微信打开链接
学习功能强大的AccessibilityService!!!
以下是本人根据自动抢红包的实现思路敲的用于微信自动向附近的人打招呼的核心代码
public class AutoService extends AccessibilityService implements View.OnClickListener {private static final String TAG = "test"; /** * 微信的包名 */ static final String WECHAT_PACKAGENAME = "com.tencent.mm"; /** * 推送消息在通知栏的关键字,设置为推送账号名,如【十点读书】 */ static final String PUSH_TEXT_KEY = "十点读书"; /** * 推送链接的关键字,所有推送链接的标题都需要包含此关键字:如【深度好文】 */ private static final String URL_TEXT_KEY = "深度好文"; /** * 向附近的人自动打招呼的内容 */ private String hello = "测试APP自动打招呼功能,这是一条测试信息"; boolean startFunc2 = false;//标记是否开启自动添加附近的人为好友的功能; int i = 0;//记录已打招呼的人数 int page=1;//记录附近的人列表页码,初始页码为1 int prepos = -1;//记录页面跳转来源,0--从附近的人页面跳转到详细资料页,1--从打招呼页面跳转到详细资料页 @Override public void onAccessibilityEvent(final AccessibilityEvent event) {int eventType = event.getEventType(); //通知栏事件 //自动打开推送的链接 if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {List<CharSequence> texts = event.getText(); if (!texts.isEmpty()) {for (CharSequence t : texts) {String text = String.valueOf(t); if (text.contains(PUSH_TEXT_KEY)) {openNotification(event); openDelay(1000, URL_TEXT_KEY); }}}}//自动加人 if (!startFunc2) {return; }if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && event.getClassName().equals("com.tencent.mm.ui.LauncherUI")) {//记录打招呼人数置零 i = 0; //当前在微信聊天页就点开发现 openNext("发现"); //然后跳转到附近的人 openDelay(1000, "附近的人"); } else if (event.getClassName().equals("com.tencent.mm.plugin.nearby.ui.NearbyFriendsUI") && eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {prepos = 0; //当前在附近的人界面就点选人打招呼 AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("米以内"); Log.d("name", "附近的人列表人数: " + list.size()); if (i < (list.size()*page) ){list.get(i%list.size()).performAction(AccessibilityNodeInfo.ACTION_CLICK); list.get(i%list.size()).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); } else if (i == list.size()*page) {//本页已全部打招呼,所以下滑列表加载下一页,每次下滑的距离是一屏 for (int i = 0; i < nodeInfo.getChild(0).getChildCount(); i++) {if (nodeInfo.getChild(0).getChild(i).getClassName().equals("android.widget.ListView")) {AccessibilityNodeInfo node_lsv = nodeInfo.getChild(0).getChild(i); node_lsv.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); page++; new Thread(new Runnable() {@Override public void run() {try {Thread.sleep(1000); } catch (InterruptedException mE) {mE.printStackTrace(); }AccessibilityNodeInfo nodeInfo_ = getRootInActiveWindow(); List<AccessibilityNodeInfo> list_ = nodeInfo_.findAccessibilityNodeInfosByText("米以内"); Log.d("name", "列表人数: "+list_.size()); //滑动之后,上一页的最后一个item为当前的第一个item,所以从第二个开始打招呼 list_.get(1).performAction(AccessibilityNodeInfo.ACTION_CLICK); list_.get(1).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); }}).start(); }}}} else if (event.getClassName().equals("com.tencent.mm.plugin.profile.ui.ContactInfoUI") && eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {if (prepos == 1) {//从打招呼界面跳转来的,则点击返回到附近的人页面 performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); i++; } else if (prepos == 0) {//从附近的人跳转来的,则点击打招呼按钮 AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); if (nodeInfo == null) {Log.w(TAG, "rootWindow为空"); return; }List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("打招呼"); if (list.size() > 0) {list.get(list.size() - 1).performAction(AccessibilityNodeInfo.ACTION_CLICK); list.get(list.size() - 1).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); } else {//如果遇到已加为好友的则界面的“打招呼”变为“发消息",所以直接返回上一个界面并记录打招呼人数+1 performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); i++; }}} else if (event.getClassName().equals("com.tencent.mm.ui.contact.SayHiEditUI") && eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {//当前在打招呼页面 prepos = 1; //输入打招呼的内容并发送 inputHello(hello); openNext("发送"); }//自动从桌面打开微信,利用微信多开助手可实现多个微信账号之间的切换 // if(topActivity.equals("com.huawei.android.launcher.Launcher")){ // openNext(event,"微信"); // AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); // nodeInfo.getChildCount(); // for (int i=0;i<nodeInfo.getChildCount();i++){ // String name=nodeInfo.getChild(i).getViewIdResourceName(); // } // } }/** * 打开通知栏消息 */ private void openNotification(AccessibilityEvent event) {if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {return; }//以下是精华,将微信的通知栏消息打开 Notification notification = (Notification) event.getParcelableData(); PendingIntent pendingIntent = notification.contentIntent; try {pendingIntent.send(); } catch (PendingIntent.CanceledException e) {e.printStackTrace(); }}/** * 点击匹配的nodeInfo * @param str text关键字 */ private void openNext(String str) {AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); if (nodeInfo == null) {Log.w(TAG, "rootWindow为空"); return; }List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText(str); Log.d("name", "匹配个数: " + list.size()); if (list.size() > 0) {list.get(list.size() - 1).performAction(AccessibilityNodeInfo.ACTION_CLICK); list.get(list.size() - 1).getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); } // if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(event.getClassName())) { // //点中了红包,下一步就是去拆红包 // checkKey1(); // } else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())) { // //拆完红包后看详细的纪录界面 // } else if ("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())) { // //在聊天界面,去点中红包 // checkKey2(); // } }//延迟打开界面 private void openDelay(final int delaytime, final String text) {new Thread(new Runnable() {@Override public void run() {try {Thread.sleep(delaytime); } catch (InterruptedException mE) {mE.printStackTrace(); }openNext(text); }}).start(); }//自动输入打招呼内容 private void inputHello(String hello) {AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); //找到当前获取焦点的view AccessibilityNodeInfo target = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT); if (target == null) {Log.d(TAG, "inputHello: null"); return; }ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("label", hello); clipboard.setPrimaryClip(clip); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {target.performAction(AccessibilityNodeInfo.ACTION_PASTE); }}@Override public void onInterrupt() {Toast.makeText(this, "服务已中断", Toast.LENGTH_SHORT).show(); }@Override protected void onServiceConnected() {super.onServiceConnected(); Toast.makeText(this, "连接服务", Toast.LENGTH_SHORT).show(); } @Override public void onCreate() {super.onCreate(); createFloatView(); }WindowManager wm; Button floatbtn; //创建悬浮按钮 private void createFloatView() {WindowManager.LayoutParams pl = new WindowManager.LayoutParams(); wm = (WindowManager) getSystemService(getApplication().WINDOW_SERVICE); pl.type = WindowManager.LayoutParams.TYPE_PHONE; pl.format = PixelFormat.RGBA_8888; pl.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; pl.gravity = Gravity.RIGHT | Gravity.BOTTOM; pl.x = 0; pl.y = 0; pl.width = 200; pl.height = 200; LayoutInflater inflater = LayoutInflater.from(this); floatbtn = (Button) inflater.inflate(R.layout.floatbtn, null); wm.addView(floatbtn, pl); floatbtn.setOnClickListener(this); }@Override public void onClick(View v) {if (startFunc2) {floatbtn.setText("启用加人"); } else {floatbtn.setText("停止加人"); }startFunc2 = !startFunc2; } }
启用这个服务的代码:
//打开系统设置中辅助功能 Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); startActivity(intent);
添加权限: <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
如果发现代码有问题,请留言,或者遇到哪里没明白的也可以在留言里交流沟通,本人看到了一定回复
demo地址:点击打开链接
实现微信自动向附近的人打招呼,实现收到指定账户推送文章时自动进入微信打开链接相关推荐
- 实现微信自动向附近的人打招呼,收到指定账户推送文章时自动进入微信打开链接
学习功能强大的AccessibilityService!!! 以下是本人根据自动抢红包的实现思路敲的用于微信自动向附近的人打招呼的核心代码 public class AutoService exten ...
- android 自动加微信,Android实现微信自动向附近的人打招呼(AccessibilityService)
学习功能强大的AccessibilityService!!! 以下是本人根据自动抢红包的实现思路敲的用于微信自动向附近的人打招呼的核心代码 public class AutoService exten ...
- 公众号向特定用户主动推送消息_SAP系统和微信集成的系列教程之三:微信用户关注公众号之后,自动在SAP C4C系统创建客户主数据...
这是Jerry 2020年的第84篇文章,也是汪子熙公众号总共第266篇原创文章. 本系列的英文版Jerry写作于2017年,这个教程总共包含十篇文章,发表在SAP社区上: https://blogs ...
- python自动推送消息_Python自动接收微信群消息并推送相应的公众号文章
原标题:Python自动接收微信群消息并推送相应的公众号文章 封面图片:<Python程序设计基础与应用>(ISBN:9787111606178),董付国,机械工业出版社 用书教师可以联系 ...
- 通过XXL-JOB定时推送bug信息到企业微信群1
通过XXL-JOB定时推送bug信息到企业微信群. 效果图 前提: 公司的Bug平台可以提供接口返回给你bug数据. 一.在企业微信群创建机器人 1.群右键创建机器人 2.拿到对应webhook. 二 ...
- php发表图片文章代码,PHP实现发表文章时自动保存图片_php
$img_array = array(); $content1 = stripslashes($content1); if (get_magic_quotes_gpc()) $content1 = s ...
- python爬虫如何实现每天爬取微信公众号的推送文章
python爬虫如何实现每天爬取微信公众号的推送文章 上上篇文章爬虫如何爬取微信公众号文章 上篇文章python爬虫如何爬取微信公众号文章(二) 上面的文章分别介绍了如何批量获取公众号的历史文章url ...
- cms自动更新php文件,织梦cms内容页修改或者删除文章之后自动更新上下篇或者首页...
织梦CMS后台修改.删除文章后自动更新首页和相应列表页.织梦后台只能开启发布后更新主页,列表,和上下页.有时候我们需要在编辑时也能更新想要的,这样不用每次去生成. 使用织梦CMS建站时我们通常会需要删 ...
- php app 推送原理,微信公众号开发的那点事第一篇——消息推送原理
微信公众平台从诞生开始到现在已经积累了海量的公众号,这其中有大量的个人运营者.为了让公众号更好滴为粉丝们服务,微信官方提供了很多接口,使用这些接口来丰富公众号的功能对于有些个人运营者来说可能并不熟悉. ...
最新文章
- Go基础知识学习(6) 接口
- Hadoop生态圈一览
- 在Silverlight中读取指定URL图片包数据
- 在eclipse中使用svn
- 教授称学习习惯的常识都是错误的
- 缺失值的处理——R语言
- 江苏计算机二级vb,江苏省计算机等级考试二级vb.ppt
- 用Elasticsearch做大规模数据的多字段、多类型索引检索
- Mongodb 可视化工具 mongochef
- 程序员为什么要写博客?怎么写博客?
- Netty权威指南(第2版)
- 游戏付费中的金融学和心理学小知识
- 苹果手机如何分享wifi密码_WiFi密码破解器 v5.1.3手机版
- CS5211 eDP转LVDS转换器芯片 CS5211芯片说明书
- 制作u盘winpe启动盘_制作U盘启动盘
- 寄存柜程序模拟(C语言)
- 路由器开启WDS模式扩展WIFI覆盖范围
- vs2013编译ffmpeg之二十六 opus、shine
- Ubuntu16.04深度学习环境搭建
- 仿射密码解密(Affine Cipher)
热门文章
- Mac 微信多开的方法
- python爬虫:使用scrapy框架抓取360超清壁纸(10W+超清壁纸等你来爬)
- React 实现Excel 文件下载(实现导入导出)
- 游戏做任务的基本流程
- 运行gulp build时报错:error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
- python爬虫学习日记(1) scrapy爬取时,报错Filtered offsite request
- 简单新颖的单片机 嵌入式 毕设项目
- 物联网——zigbee(cc2530)
- 戴尔服务器R730XD增加万兆光卡后风扇满速运转解决办法
- 使用matlab求离散系统的频率响应分析和零、极点分布