如何在whatsapp业务中自动单击发送按钮

o7jaxewo  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(432)

我在一个whatsapp项目工作,我有一个无障碍服务,可以点击whatsapp正常发送按钮,但它不做whatsapp业务。有人知道为什么吗?
我也设法打开whatsapp的业务,但只是没有按下发送按钮。

import android.accessibilityservice.AccessibilityService;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import java.util.List;
public class WhatAppAccessibilityService extends AccessibilityService {
public static String AccessOnOff;
public void onStart(Intent intent, int startid){
super.onStart(intent, startid);
Bundle b =intent.getExtras();
AccessOnOff = b.getString("AccessibilityControl");
}

Override
public void onAccessibilityEvent (AccessibilityEvent event) {

AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
if (getRootInActiveWindow() == null) {
return;
}

// Whatsapp send button id
List<AccessibilityNodeInfoCompat> sendMessageNodeInfoList = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp.w4b:id/send");
if (sendMessageNodeInfoList == null || sendMessageNodeInfoList.isEmpty()) {
return;
}

AccessibilityNodeInfoCompat sendMessageButton = sendMessageNodeInfoList.get(0);
if (!sendMessageButton.isVisibleToUser()) {
return;
}

// Now fire a click on the send button
sendMessageButton.performAction(AccessibilityNodeInfo.ACTION_CLICK);
// Now go back to your app by clicking on the Android back button twice:
// First one to leave the conversation screen
// Second one to leave whatsapp
try {
Thread.sleep(900); // hack for certain devices in which the immediate back click is too fast to handle
performGlobalAction(GLOBAL_ACTION_BACK);
Thread.sleep(400); // same hack as above
performGlobalAction(GLOBAL_ACTION_BACK);
//Thread.sleep(100); // same hack as above
//performGlobalAction(GLOBAL_ACTION_BACK);
} catch (InterruptedException ignored) {
}

/*
Context ctx=getApplicationContext();
Intent i =ctx.getPackageManager().getLaunchIntentForPackage("net.trices.autosmssender");
ctx.startActivity(i);

* /

//performGlobalAction (GLOBAL_ACTION_BACK);
}

@Override
public void onInterrupt() {

}
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题