gpt4 book ai didi

java - 有没有办法使用 AccessibilityService 单击对话框中的超链接?

转载 作者:行者123 更新时间:2023-12-01 16:22:55 25 4
gpt4 key购买 nike

permission prompt image

我正在尝试使用应用程序的辅助功能服务来单击“设置中允许”。我查看了 AccessibilityNode,但在 TextView 中没有看到任何可交互的内容。这是节点的输出:

Event Type: TYPE_WINDOW_CONTENT_CHANGED com.google.android.permissioncontroller android.widget.FrameLayout
Source:
0 | class name: android.widget.FrameLayout text: null content description: null input type 0 actions: ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_SHOW_ON_SCREEN
1 | class name: android.widget.ScrollView text: null content description: null input type 0 actions: ACTION_FOCUS, ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_SHOW_ON_SCREEN
2 | class name: android.widget.TextView text: Change location access for AppName? content description: null input type 0 actions: ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, ACTION_SET_SELECTION, ACTION_SHOW_ON_SCREEN
2 | class name: android.widget.TextView text: This app wants to access your location all the time, even when you’re not using the app. Allow in settings. content description: null input type 0 actions: ACTION_FOCUS, ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, ACTION_SET_SELECTION, ACTION_SHOW_ON_SCREEN
2 | class name: android.widget.Button text: Keep “While the app is in use” content description: null input type 0 actions: ACTION_FOCUS, ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_CLICK, ACTION_ACCESSIBILITY_FOCUS, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, ACTION_SET_SELECTION, ACTION_SHOW_ON_SCREEN

TextView 只有少数可用的操作。据我所知,我已尝试了可用的操作,但没有成功。

我还探索了“在设置中允许”部分的直接 Intent 的想法,但目前还没有。我们的应用程序要求位置信息始终处于开启状态。

最佳答案

所以我最终做的是编写一个静态函数来从 CharSequence 获取跨度

@NonNull
ClickableSpan[] getClickableSpans(CharSequence text) {
try {
if (text instanceof Spanned) {
Spanned spanned = (Spanned) text;
return spanned.getSpans(0, text.length(), ClickableSpan.class);
}
} catch (Exception e) {
//log exception
}
return new ClickableSpan[0];
}

并使用它

public void onAccessibilityEvent(AccessibilityEvent) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if (nodeInfo != null) {
List<AccessibilityNodeInfo> nodeInfoList = nodeInfo.findAccessibilityNodeInfosByText(
"This app wants to access your location all the time, even when you're not using the app. Allow in settings.");
if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
ClickableSpan[] spans = getClickableSpans(nodeInfoList.get(0).getText());
if (spans.length > 0) {
spans[0].onClick(null);
}
}
}
}

关于java - 有没有办法使用 AccessibilityService 单击对话框中的超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62219663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com