你想要做的是以下。
使用無障礙服務跟蹤傳入事件。然後,您想要跟蹤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;
}
你救了我的屁股@chriscm。謝謝一個男人! –
@PraneetKumar您可以請您分享代碼確切地瞭解您如何跟蹤Flipkart產品詳細信息頁面?用戶第一次打開產品詳細信息頁面時以及用戶從onPause()到onResume()時的跟蹤方式,因爲在這兩種情況下都會調用不同的事件? – Mahesh