(二)实现成果:
- 锁屏抢红包(不行以有暗码可能图案之类的锁屏)
- 口令红包,自动输进口令而且发送
- 抢完红包后,自动回覆感激语,可在红包配置里自行配置内容
- 其他的成果就没继承往下做了,知道要领,其他都也许逐步研究出来。
(三)操作抢红包帮助成果类完成QQ抢红包,类中有效到QQConstant类,代码如下:
- /**
- * 描写:QQ抢红包揽事
- */
- public class EnvelopeService extends BaseAccessibilityService {
-
- //锁屏、解锁相干
- private KeyguardManager.KeyguardLock kl;
-
- //叫醒屏幕相干
- private PowerManager.WakeLock wl = null;
-
- private long delayTime = 0;//耽误抢的时刻
-
- /**
- * 描写:全部变乱相应的时辰会回调
- */
- @Override
- public void onAccessibilityEvent(AccessibilityEvent event) {
-
- //验证抢红包的开关
- if (!invalidEnable()) {
- return;
- }
-
- //变乱范例
- int eventType = event.getEventType();
-
- //获取包名
- CharSequence packageName = event.getPackageName();
- if (TextUtils.isEmpty(packageName)) {
- return;
- }
-
- switch (eventType) {
-
- //状态栏变革
- case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
-
- if (QQConstant.QQ_PACKAGE_NAME.equals(packageName)) {
- //处理赏罚状态栏上QQ的动静,假如是红包就跳转已往
- progressQQStatusBar(event);
- }
- break;
-
- //窗口切换的时辰回调
- case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
- case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
- if (QQConstant.QQ_PACKAGE_NAME.equals(packageName)) {
- //处理赏罚正在QQ谈天窗口页面,有其他群可强人有新的红包提示,跳转已往。
- progressNewMessage(event);
- //处理赏罚谈天页面的红包
- progressQQChat(event);
- }
-
- break;
- }
-
-
- }
-
- /**
- * 描写:处理赏罚新动静
- */
- private void progressNewMessage(AccessibilityEvent event) {
-
- if (event == null) {
- return;
- }
- AccessibilityNodeInfo source = event.getSource();
- if (source == null) {
- return;
- }
- //按照event的source里的text,来判定这个动静是否包括[QQ红包]的字眼,有的话就跳转已往
- CharSequence text = source.getText();
- if (!TextUtils.isEmpty(text) && text.toString().contains(QQConstant.QQ_ENVELOPE_KEYWORD)) {
- performViewClick(source);
- }
- }
-
- /**
- * 描写:验证抢红包是否开启
- */
- private boolean invalidEnable() {
- return SettingConfig.getInstance().getReEnable();
- }
-
-
- /**
- * 描写:处理赏罚QQ状态栏
- */
- public void progressQQStatusBar(AccessibilityEvent event) {
- List<CharSequence> text = event.getText();
- //开始检索界面上是否有QQ红包的文本,而且他是关照栏的信息
- if (text != null && text.size() > 0) {
- for (CharSequence charSequence : text) {
- if (charSequence.toString().contains(QQConstant.QQ_ENVELOPE_KEYWORD)) {
- //声名存在红包弹窗,马长进去
- if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
- Notification notification = (Notification) event.getParcelableData();
- if (notification == null) {
- return;
- }
- PendingIntent pendingIntent = notification.contentIntent;
- if (pendingIntent == null) {
- return;
- }
- try {
- //要跳转之前,先举办解锁屏幕,然后再跳转,有也许你此刻屏幕是锁屏状态,先举办解锁,然后打开页面,有暗码的也许就不可了
- wakeUpAndUnlock(MyApp.context);
- //跳转
- pendingIntent.send();
- } catch (PendingIntent.CanceledException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
-
- /**
- * 描写:处理赏罚QQ谈天红包
- */
- public void progressQQChat(AccessibilityEvent event) {
-
- if (TextUtils.isEmpty(event.getClassName())) {
- return;
- //假如当前页面是谈天页面可能当前的描写信息是"返回动静界面",就必定是对话页面
- }
-
- //验证当前变乱是否切合查询页面上的红包
- if (!invalidEnvelopeUi(event)) {
- return;
- }
-
- //耽误点击红包,防备被检测到开了抢红包,不外感受照旧感受会被检测到,应该有的结果吧...
- try {
- Thread.sleep(delayTime);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- //平凡红包,检索点击拆开的字眼。
- List<AccessibilityNodeInfo> envelope = findViewListByText(QQConstant.QQ_CLICK_TAKE_APART, false);
- //处理赏罚平凡红包
- progressNormal(envelope);
-
- //口令红包,检索口令红包的字眼。
- List<AccessibilityNodeInfo> passwordList = findViewListByText(QQConstant.QQ_CLICK_PASSWORD_DIALOG, false);
- //处理赏罚口令红包
- progressPassword(passwordList);
- }
-
-
- /**
- * 描写:验证是否此刻是在谈天页面,可以举办抢红包处理赏罚
- * @param event
- */
-
- public boolean invalidEnvelopeUi(AccessibilityEvent event) {
-
- //判定类名是否是谈天页面
- if (!QQConstant.QQ_IM_CHAT_ACTIVITY.equals(event.getClassName().toString())) {
- return true;
- }
-
- //判定页面中的元素是否有点击拆开的文本,有就返回可以举办查询了
- int recordCount = event.getRecordCount();
- if (recordCount > 0) {
- for (int i = 0; i < recordCount; i++) {
- AccessibilityRecord record = event.getRecord(i);
- if (record == null) {
- break;
- }
- List<CharSequence> text = record.getText();
- if (text != null && text.size() > 0 && text.contains(QQConstant.QQ_CLICK_TAKE_APART)) {
- //假如文本中有点击拆开的字眼,就返回可以举办查询了
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * 回到体系桌面
- */
- private void back2Home(int time) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Intent home = new Intent(Intent.ACTION_MAIN);
- home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- home.addCategory(Intent.CATEGORY_HOME);
- startActivity(home);
- }
-
- /**
- * 描写:处理赏罚平凡红包
- */
- public void progressNormal(List<AccessibilityNodeInfo> passwordList) {
- if (passwordList != null && passwordList.size() > 0) {
- for (AccessibilityNodeInfo accessibilityNodeInfo : passwordList) {
- if (accessibilityNodeInfo != null && !TextUtils.isEmpty(accessibilityNodeInfo.getText()) && QQConstant.QQ_CLICK_TAKE_APART.equals(accessibilityNodeInfo.getText().toString())) {
-
- //点击拆开红包
- performViewClick(accessibilityNodeInfo);
-
- //回覆感激信息,按照设置文件中设置的回回音息回覆
- String reReplyMessage = SettingConfig.getInstance().getReReplyMessage();
- if (!TextUtils.isEmpty(reReplyMessage)) {
- replyMessage(reReplyMessage);
- }
- }
- }
- //最后耽误变乱触发返回变乱,封锁红包页面
- performBackClick(1200);
- }
- }
-
- /**
- * 描写:处理赏罚口令红包
- * @param passwordList
- */
- public void progressPassword(List<AccessibilityNodeInfo> passwordList) {
- if (passwordList != null && passwordList.size() > 0) {
- for (AccessibilityNodeInfo accessibilityNodeInfo : passwordList) {
- if (accessibilityNodeInfo != null && !TextUtils.isEmpty(accessibilityNodeInfo.getText()) && QQConstant.QQ_CLICK_PASSWORD_DIALOG.equals(accessibilityNodeInfo.getText().toString())) {
- //假如口令红包存在,就在输入框中举办输入,然后发送
- AccessibilityNodeInfo parent = accessibilityNodeInfo.getParent();
- if (parent != null) {
- CharSequence contentDescription = parent.getContentDescription();
- if (!TextUtils.isEmpty(contentDescription)) {
- //1. 获取口令
- String key = (String) contentDescription;
- if (key.contains(",") && key.contains("口令:")) {
- key = key.substring(key.indexOf("口令:") + 3, key.lastIndexOf(","));
- }
- Log.e("口令", key);
-
- //2. 填写口令到编辑框上然后举办发送
- replyMessage(key);
-
- //返回,封锁红包页面
- performBackClick(1200);
- }
- }
- }
- }
- }
- }
-
-
- /**
- * 叫醒屏幕并解锁权限
- * <uses-permission android:name="android.permission.WAKE_LOCK" />
- */
- @SuppressLint("Wakelock")
- @SuppressWarnings("deprecation")
- public void wakeUpAndUnlock(Context context) {
- // 点亮屏幕
- wl.acquire();
- // 开释
- wl.release();
- // 解锁
- kl.disableKeyguard();
- }
-
- /**
- * 描写:回覆动静,无耽误
- */
- public void replyMessage(String key) {
- replyMessage(key, 0);
- }
-
- /**
- * 描写:回覆动静
- */
- public void replyMessage(String key, int time) {
-
- //耽误
- if (time > 0) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- //获取QQ谈天页面输入框
- AccessibilityNodeInfo chat_edit = findViewByID(QQConstant.QQ_CHAT_MESSAGE_INPUT);
- if (chat_edit != null) {
-
- //把口令粘贴到输入框中
- pastaText(chat_edit, MyApp.context, key);
-
- //获取QQ谈天页面发送动静按钮
- AccessibilityNodeInfo sendMessage = findViewByID(QQConstant.QQ_CHAT_MESSAGE_SEND);
-
- //然后就按下发送按钮
- if (sendMessage != null && Button.class.getName().equals(sendMessage.getClassName())) {
- performViewClick(sendMessage);
- }
- }
-
- }
-
- @Override
- public void onInterrupt() {
- }
-
-
- @Override
- protected void onServiceConnected() {
- super.onServiceConnected();
-
- // 获取电源打点器工具
- PowerManager pm = (PowerManager) MyApp.context
- .getSystemService(Context.POWER_SERVICE);
- // 获取PowerManager.WakeLock工具,后头的参数|暗示同时传入两个值,最后的是调试用的Tag
- wl = pm.newWakeLock(
- PowerManager.ACQUIRE_CAUSES_WAKEUP
- | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
-
- KeyguardManager km = (KeyguardManager) MyApp.context.getSystemService(Context.KEYGUARD_SERVICE);
- kl = km.newKeyguardLock("unLock");
-
- //初始化屏幕的监听
- ScreenListener screenListener = new ScreenListener(MyApp.context);
- screenListener.begin(new ScreenListener.ScreenStateListener() {
- @Override
- public void onScreenOn() {
- Log.e("ScreenListener", "屏幕打开了");
- }
-
- @Override
- public void onScreenOff() {
- //在屏幕封锁的时辰,举办锁屏,不执行的话,锁屏就失效了,由于要实现锁屏状态下也可以举办抢红包。
- Log.e("ScreenListener", "屏幕封锁了");
- if (kl != null) {
- kl.disableKeyguard();
- kl.reenableKeyguard();
- }
- }
-
- @Override
- public void onUserPresent() {
- Log.e("ScreenListener", "解锁了");
- }
- });
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- }
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|