• 辅助


    package com.example.test01;
    
    import java.util.List;
    
    import android.R.bool;
    import android.accessibilityservice.AccessibilityService;
    import android.accessibilityservice.AccessibilityServiceInfo;
    import android.app.Notification;
    import android.app.PendingIntent;
    import android.app.PendingIntent.CanceledException;
    import android.view.accessibility.AccessibilityEvent;
    import android.view.accessibility.AccessibilityNodeInfo;
    
    public class MyAccessibilityService extends AccessibilityService {
    
        
        @Override
        public void onAccessibilityEvent(AccessibilityEvent arg0) {
            int eventyp = arg0.getEventType();
            if (eventyp == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
                List<CharSequence> texts = arg0.getText();
                if (texts != null) {
    
                    for (CharSequence charSequence : texts) {
                        //获取通知栏的标题
                        String string = String.valueOf(charSequence);
                    
                        if (string.contains("快抢单")) {
    
                            if (arg0.getParcelableData() == null || !(arg0.getParcelableData() instanceof Notification)) {
                                return;
                            }
                            
                            //模拟点击通知栏直接跳入Activity
                            Notification notification = (Notification) arg0.getParcelableData();
                            PendingIntent pendingIntent = notification.contentIntent;
                            try {
                                pendingIntent.send();
                            } catch (CanceledException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
    
            } else if (eventyp == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                
            
                if ("com.homelink.ui.app.arrange.BookShowActivity".equals(arg0.getClassName())) {
                    
                    if (getRootInActiveWindow() == null) {
                        
                        return;
                    }
                    
                    boolean isEnd=true;
                    List<AccessibilityNodeInfo> list=null;
                    while (isEnd) {
                        list = getRootInActiveWindow().findAccessibilityNodeInfosByText("赶紧抢"); 
                        if (list.size()>0) {
                            isEnd=false;
                        }
                    }
                     
                    for(int i=0;i<list.size();i++){
                        AccessibilityNodeInfo parent = list.get(i);  
                        if (parent.getClassName().equals("android.widget.Button")&&parent.isEnabled()) {  
                            parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);  
                        }
                    }
                }
            }
    
        }
    
        @Override
        public void onInterrupt() {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        protected void onServiceConnected() {
            // TODO Auto-generated method stub
            super.onServiceConnected();
            AccessibilityServiceInfo info = getServiceInfo();
            info.notificationTimeout = 100;
            info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
            info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
            info.packageNames = new String[] { "com.homelink.im" };
            setServiceInfo(info);
    
        }
    
    }
  • 相关阅读:
    Jenkins自动化部署入门详细教程
    单元测试
    弱网测试
    Token、Cookie和Session
    测试开发人员必备Linux命令
    TestNG(一)
    char和varchar
    你平时会看日志吗,一般会出现哪些异常(Exception)
    内存溢出和内存泄漏的区别,产生原因以及解决方案
    测试一个电梯
  • 原文地址:https://www.cnblogs.com/qcgAd/p/5784610.html
Copyright © 2020-2023  润新知