簡體   English   中英

Android 輔助功能執行觸摸操作

[英]Android Accessibility perform touch action

我想知道是否可以使用 Android 無障礙服務在屏幕上的位置執行觸摸操作,例如:

Bundle arguments = new Bundle();
arguments.putInt(/*coord X*/, /*X value*/);
arguments.putInt(/*coord Y*/, /*Y value*/);
node.performAction(/*touch action*/, arguments);

或者,如果可能,再次記錄用戶點擊某個視圖/位置時的操作。

基本上,我必須在軟鍵盤上執行操作,當它彈出時(外部應用程序沒有“提交”按鈕來執行 ACTION_CLICK),但由於安全策略,不允許注入事件。 有什么想法嗎? 謝謝!

您不能按屏幕上的位置執行任何操作,您只能在節點上執行任何操作,但是您可以通過使用getBoundsInScreen遞歸檢查屏幕上的節點位置來找到哪個節點在您的坐標上。

如果它是 OpenGL 游戲,它將不起作用,並且您將無法僅在您在該位置找到的節點上執行對精確位置的單擊。

//touch function

public void touchTo(int x, int y) {
    Path swipePath = new Path();
    swipePath.moveTo(x, y);
    swipePath.lineTo(x, y);
    GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
    gestureBuilder.addStroke(new GestureDescription.StrokeDescription(swipePath, 0, 50));
    dispatchGesture(gestureBuilder.build(), null, null);
}

// 它在我的類 SupporterService 中工作,擴展了 AccessibilityService。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM