通过我的应用阅读其他应用的内容

时间:2016-03-08 13:02:34

标签: android service background accessibilityservice

我几天都在搜索同样的问题。但无法得到任何暗示。

我需要创建一个类似voodoo app的应用程序,它只在不同应用程序的特定页面上显示其自定义布局,如flipkart等。

现在,直到这个时候,我已经找到了使用AccessebilityService和MediaProjection类的选项。但是我被卡住了,我怎么能以编程方式知道,Flipkart的产品详细信息页面是可见的,这样我就可以像Voodoo应用程序一样显示我的应用程序的自定义视图。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您想要做的是以下内容。

使用辅助功能服务跟踪传入的事件。然后,您希望跟踪TYPE_WINDOW_CONTENT_CHANGED个事件,并检测窗口内容何时符合您的期望。

@Override
public void onAccessibilityEvent(AccessibilityEvent e) {

    switch (e.getEventType()) {
        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:  {
            if (isFlipkartProdcutDetailPage(getRootInActiveWindow()) {
                doStuff()
            }
        }
    }
}
public boolean isFlipkartProductDetailPage(AccessibilityNodeInfo nodeInfo) {
    //Use the node info tree to identify the proper content.
    //For now we'll just log it to logcat.
    Log.w("TAG", toStringHierarchy(nodeInfo, 0));
}

private String toStringHierarchy(AccessibilityNodeInfo info, int depth) {
    if (info == null) return "";

    String result = "|";
    for (int i = 0; i < depth; i++) {
        result += "  ";
    }

    result += info.toString();

    for (int i = 0; i < info.getChildCount(); i++) {
        result += "\n" + toStringHierarchy(info.getChild(i), depth + 1);
    }

    return result;
}