java - 我的辅助功能服务只工作一次,有些没用
问题描述
我正在研究一个名为 whatsapp 自动化的项目,其中在 whatsapp 上发送单个或多个消息,而无需单击 whatsapp 的发送按钮。
这是我的无障碍课程
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
if(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == accessibilityEvent.getEventType());
AccessibilityNodeInfo nodeInfo = accessibilityEvent.getSource();
if(nodeInfo == null){
return;
}
Log.d("Saad", "Accessibility : "+ nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send"));
List<AccessibilityNodeInfo> sendmessgeNodeListImage = nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send");
for(int i = 0; i<sendmessgeNodeListImage.size(); i++){
AccessibilityNodeInfo node = sendmessgeNodeListImage.get(i);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}if(sendmessgeNodeListImage == null){
return;
} try{
Thread.sleep(1000);
performGlobalAction(GLOBAL_ACTION_BACK);
Thread.sleep(1000);
}catch (InterruptedException ignored){ }
performGlobalAction(GLOBAL_ACTION_BACK);
}
这是 Intent 调用的地方
for (int j = 0; j < MobileNumber.size(); j++) {
Log.d("Saad", ""+j);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/*");
sendIntent.putExtra(Intent.EXTRA_TEXT, message.getText().toString());
sendIntent.putExtra("jid", MobileNumber.get(j) + "@s.whatsapp.net");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
这是xml文件
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeWindowContentChanged|typeWindowStateChanged|typeViewTextChanged"
android:packageNames="com.whatsapp"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="1000"
android:canRetrieveWindowContent="true"/>
解决方案
推荐阅读
- javascript - 如何选择axios自带的元素?
- javascript - 自动点击页面加载
- excel - 如何使用具有多个范围条件的 if 函数
- javascript - Javascript - 有什么更好的方法来转换循环?
- laravel - Laravel,计数集合,其中关系字段等于值
- email - 无论邮件客户端或响应类型(转发或回复)如何,我们都可以依赖它来将信息存储到其中的电子邮件标题
- elasticsearch - 删除旧索引的索引生命周期策略
- spring - Spring Data findFirstByLastNameIsNull()不起作用
- flutter - 自定义颤振图标
- c++ - QT 小部件 视频作为背景?