如何捕获浏览器活动?

Les*_*ova 6 android

我有一个应用程序,它是下一个方式启动浏览器:

 Uri uri = Uri.parse(getURL());
    Context context = widget.getContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

我有另一个AndroidJUnit项目,我希望在其中捕获该活动.

接下来的步骤,我可以捕获运行浏览器的MYProjectActivity,但我无法捕获浏览器.

 Instrumentation instrumentation = getInstrumentation();

  // Register we are interested in the authentication activiry...
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(MYProjectActivity.class.getName(), null, false);

  // Start the authentication activity as the first activity...
  Intent intent = new Intent(Intent.ACTION_MAIN);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(instrumentation.getTargetContext(), MYProjectActivity.class.getName());
  instrumentation.startActivitySync(intent);

  // Wait for it to start...
  Activity currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
Run Code Online (Sandbox Code Playgroud)

有人知道怎么做这个吗?

Jon*_*Jon 0

我不确定如何按照您的要求监控浏览器,但提供另一种想法:

您需要权衡一下使用浏览器的原因是什么,但是您是否考虑过使用WebView来代替?它允许您进行更多控制,因为您可以将其放入 Activity 中并观察意图流量以及子类 WebView 以获取更详细的回调信息(如果您需要)。