无法使用Android可访问性服务在WhatsApp EditText中编辑文本
当我们与图像一起发送文本时,我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论