autox.js 实现遍历微信聊天列表 并发送固定消息

1 怎么找到界面上的聊天item?

每个item左边都有一张图片,通过获取图片并判断图片的位置来确定是否是聊天item。

关键代码:

js 复制代码
 var iconList = className("android.widget.ImageView").find();
  
 for(var i =0;i<iconList.length;i++){
        var icon = iconList[i];

        var icon = iconList[i];
        var iconBottom = icon.bounds().bottom;
        var iconHeight = icon.bounds().height;
        var right = icon.bounds().right;

        if(right > deviceWidth / 4){
            continue;
           }
   
        if(iconBottom < topHeight || iconHeight < 50){
           continue;
        }

        if((icon.parent() != null && icon.parent().className() == "android.widget.RelativeLayout" )
        && (icon.parent().parent() != null && icon.parent().parent().className() == "android.widget.LinearLayout" )
        && (icon.parent().parent().parent() != null &&  icon.parent().parent().parent().className() == "android.widget.LinearLayout" )
        && (icon.parent().parent().parent().parent() != null && icon.parent().parent().parent().parent().className() == "android.widget.ListView" )
        ){
            var item = icon.parent().parent().parent();
            var itemWidth = item.bounds().width();
            var itemHeight = item.bounds().height();
            if(itemWidth < device.width * 0.9)continue;
            activeItemList.push(item)
        }
    }

2 怎么滑动保证不会多滑动或者少滑动

通过swipe操作,swipe操作可以指定滑动距离。

js 复制代码
 for(var i =0;i<activeItemList.length;i++){
    
            var item = activeItemList[i];
            var itemWidth = item.bounds().width();
            var itemHeight = item.bounds().height();
            var itemBototom = item.bounds().bottom;
            if(itemWidth < 900)continue;
            var eachItemHeight = itemHeight;
        
            item.click();
            console.log("=======itemClick====");
       
            openChatAndSend()
            sleep(200);
            console.log("=======itemBack");
            checkIsMainPage();
            var scrollHeight  = eachItemHeight;
            if(isFirstScroll){
                isFirstScroll = false;
                scrollHeight = itemBototom - topHeight;
            }
        
            swipe(device.width / 2, device.height / 2 , device.width / 2 , device.height/2 - scrollHeight, 100);
    
            if(maxIconBottom < item.bounds().bottom){
                maxIconBottom = item.bounds().bottom;
            }
    
           
        // }else {
        //     console.log("======jump333")
        // }
    }

3 怎么判断滑动到底部了。当滑动到底部的时候,最后一个item的Bottom是小于device.height的。可以用这个为依据。

js 复制代码
 if(maxIconBottom < device.height){
        isReachBottom = true
    }

4 怎么判断滑动到顶部?

这里取巧,只有滑动到顶部的时候plus_icon才能找到。

js 复制代码
function scrollToTop(listView){
    var topAddIcon = id("plus_icon").findOne(200);
    while(topAddIcon == null){
        listView.scrollBackward();
        topAddIcon = id("plus_icon").findOne(200);
    }
}

5 跳转到聊天界面,怎么输入文字。

找到输入框,然后settext

js 复制代码
    var enter = className("android.widget.EditText").findOne(400)

    if(enter == null){
        back()
        return;
    };
    enter.setText("😄")

6 怎么发送

js 复制代码
   var sendButton = className("android.widget.Button").text("发送").findOne(400);
//    if(sendButton != null){
//     sendButton.click()
//    }

7 怎么返回

这里一定要用Back() 不然会发现返回去之后,找不到聊天item了。

js 复制代码
back()

效果图:

相关推荐
不急不躁1231 小时前
Android16 GTS GtsPermissionTestcases 测试,跳过权限检查
android
符哥20083 小时前
关于用Android Compose开发成不成熟的分析
android·android jetpack
蜗牛、Z3 小时前
Android 蓝牙/Wi-Fi通信协议之:蓝牙扫描ScanCallback详解
android
黄昏晓x3 小时前
Linux----进程控制
android·linux·运维
我是阿亮啊4 小时前
android中事件分发机制
android·事件分发·事件分发机制
心前阳光5 小时前
Unity 模拟父子关系
android·unity·游戏引擎
2501_915106325 小时前
当 Perfdog 开始收费之后,我重新整理了一替代方案
android·ios·小程序·https·uni-app·iphone·webview
多多*5 小时前
2月3日面试题整理 字节跳动后端开发相关
android·java·开发语言·网络·jvm·adb·c#
习惯就好zz6 小时前
[Android/Linux] 实战记录:利用 Kconfig 精确控制 i.MX8MM 特定 DTB 的编译生成
android·linux·dts·dtb·lunch·多卡板配置
踏雪羽翼7 小时前
android 解决混淆导致AGPBI: {“kind“:“error“,“text“:“Type a.a is defined multiple times
android·java·开发语言·混淆·混淆打包出现a.a