无法使用Android可访问性服务在WhatsApp EditText中编辑文本

发布于 2025-01-28 09:49:10 字数 2040 浏览 4 评论 0原文

当我们与图像一起发送文本时,我正在尝试在WhatsApp中的EditText中编辑文本。然后通过单击Android可访问性服务单击“发送”按钮将其发送。但是问题在于,EditText中的文本已修改,但是在单击“发送”按钮时,旧文本与图像一起发送。对此的任何帮助将不胜感激。谢谢。

class WhatsappAccessibilityService : AccessibilityService() {

override fun onAccessibilityEvent(event: AccessibilityEvent?) {
    val nodeInfo = event?.source ?: return
    val editMessageNodeList =
        nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/caption")
   

    if (editMessageNodeList.isEmpty()) {
        return
    }
    for (editMessage in editMessageNodeList) {
        if (editMessage.className.equals("android.widget.EditText")) {
             val message = editMessage.text.toString()
            val suffix: String = "some text"
            if (message.endsWith(suffix)) {
                val bundle = Bundle()
                val newMessage = message.replace(suffix, "")
                bundle.putString(
                    AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
                    newMessage
                )
                editMessage.performAction(
                    AccessibilityNodeInfoCompat.ACTION_SET_TEXT,
                    bundle
                )
            }
            val sendMessageNodeList = nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send")

            for (node in sendMessageNodeList!!) {
                if (!node.isVisibleToUser) {
                    return
                }
                node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
                try {
                    Thread.sleep(700)
                    performGlobalAction(GLOBAL_ACTION_BACK)
                    Thread.sleep(700)
                    performGlobalAction(GLOBAL_ACTION_BACK)
                } catch (ignored: InterruptedException) {
                    Log.d("TAG", "onAccessibilityEvent: exception $ignored ")
                }
            }
        }
    }
}

override fun onInterrupt() {
    Log.d("TAG", "onInterrupt: ")
}

}

I am trying to edit the text in the edittext in whatsapp when we send a text along with an image. And then send it by clicking the send button through Android Accessibility Service. But the problem is that the text in the EditText is modified but on clicking the send button the old text is sent along with the image. Any help on this would be appreciated. thanks.

class WhatsappAccessibilityService : AccessibilityService() {

override fun onAccessibilityEvent(event: AccessibilityEvent?) {
    val nodeInfo = event?.source ?: return
    val editMessageNodeList =
        nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/caption")
   

    if (editMessageNodeList.isEmpty()) {
        return
    }
    for (editMessage in editMessageNodeList) {
        if (editMessage.className.equals("android.widget.EditText")) {
             val message = editMessage.text.toString()
            val suffix: String = "some text"
            if (message.endsWith(suffix)) {
                val bundle = Bundle()
                val newMessage = message.replace(suffix, "")
                bundle.putString(
                    AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
                    newMessage
                )
                editMessage.performAction(
                    AccessibilityNodeInfoCompat.ACTION_SET_TEXT,
                    bundle
                )
            }
            val sendMessageNodeList = nodeInfo.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send")

            for (node in sendMessageNodeList!!) {
                if (!node.isVisibleToUser) {
                    return
                }
                node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
                try {
                    Thread.sleep(700)
                    performGlobalAction(GLOBAL_ACTION_BACK)
                    Thread.sleep(700)
                    performGlobalAction(GLOBAL_ACTION_BACK)
                } catch (ignored: InterruptedException) {
                    Log.d("TAG", "onAccessibilityEvent: exception $ignored ")
                }
            }
        }
    }
}

override fun onInterrupt() {
    Log.d("TAG", "onInterrupt: ")
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文