我的辅助功能服务只工作一次,有些不起作用

时间:2021-04-25 15:54:18

标签: java android whatsapp accessibilityservice

我正在开发一个名为 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"/>

0 个答案:

没有答案
相关问题