【问题标题】:Android - ActivityMonitor getHits() always return zeroAndroid - ActivityMonitor getHits() 总是返回零
【发布时间】:2014-05-09 08:55:39
【问题描述】:

这里是测试代码:

    Instrumentation inst = getInstrumentation();
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_VIEW);
    intentFilter.addDataScheme("http://");
    intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);
    ActivityMonitor monitor = inst.addMonitor(intentFilter, null, false);
    assertEquals(0, monitor.getHits());

    homeViewController.onItemClick(null, null, 5, 0);
    monitor.waitForActivityWithTimeout(5000);
    assertEquals(1, monitor.getHits());
    inst.removeMonitor(monitor);

这是经过测试的代码:

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_VIEW);
    sendIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    sendIntent.setData(Uri.parse(getString(R.string.my_website)));
    startActivity(sendIntent);

getHits() 总是返回零。我没有使用任何第三个库。

【问题讨论】:

  • 如果你查看那里的答案,你会发现原因是使用了Robotium的Solo。 “我没有使用任何第三方库”。
  • 赏金也帮不上忙?!
  • 能否请您在声明意图过滤器的位置发布您的 xml。我可能会超越自己,但意图过滤器是否也需要主机和路径前缀?
  • 我没有在 XML 中创建任何意图过滤器。代码中的意图过滤器仅用于“单元测试”代码。

标签: android instrumentation activity-monitor


【解决方案1】:

这个问题已经存在了一段时间,但想提供一个对我有用的解决方案。

intentFilter.addDataScheme("http://") 不对,应该改成intentFilter.addDataScheme("http") 就好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多