gpt4 book ai didi

android - 使用 AccessibilityNodeInfo 导致堆栈大小 8MB 错误

转载 作者:太空狗 更新时间:2023-10-29 14:36:48 25 4
gpt4 key购买 nike

我使用辅助功能服务将所有文本显示在屏幕上。正常工作几分钟后,它导致了一些 GC allocated... 日志的 ANR,几秒钟后,它崩溃并出现以下错误: enter image description here

@Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
try {
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (powerManager == null || !powerManager.isInteractive()) {
return;
}
if (FirebaseAuth.getInstance().getCurrentUser() == null) return;
CharSequence eventPackageName = event.getPackageName();
if (eventPackageName != null) {
if (eventPackageName.equals(BuildConfig.APPLICATION_ID)) return;
if (eventPackageName.equals(getCurrentKeyboardPackageName())) return;
int eventType = event.getEventType();
if (eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
AccessibilityNodeInfo mNodeInfo = event.getSource();
StringBuilder stringBuilder = new StringBuilder("");
getAllTextViews(mNodeInfo, stringBuilder);
String value = stringBuilder.toString().replace('\n', ' ').replaceAll(" +", " ");
}

}
} catch (Exception e) {
e.printStackTrace();
}
}

我的 getAllTextViews() 方法:

private void getAllTextViews(AccessibilityNodeInfo nodeInfo, StringBuilder stringBuilder) {
if (nodeInfo == null) return;
if (!TextUtils.isEmpty(nodeInfo.getText())) {
stringBuilder.append(" " + nodeInfo.getText());
}
for (int i = 0; i < nodeInfo.getChildCount(); i++) {
getAllTextViews(nodeInfo.getChild(i), stringBuilder);
}
}

任何帮助将不胜感激。非常感谢!

最佳答案

你需要的是在信息被使用后使用AccessibilityNodeInforecycle()方法。

关于android - 使用 AccessibilityNodeInfo 导致堆栈大小 8MB 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54102169/

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