如何解决如何在 Whatsapp Business 中自动点击发送按钮
我正在做一个 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() {
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。