How to catch browser activity?

I have an application that launches a browser as follows:

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); 

I have another AndroidJUnit project in which I want to catch this activity.

With the following steps, I can catch MYProjectActivity, which launches the browser, but I could not catch the browser.

  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); 

Does anyone know how to do this?

+6
source share
1 answer

I'm not sure how to control the browser as you request, but offering an alternative thought:

You need to weigh your reasons for using a browser, but have you thought of using WebView instead ? This allows you much more control, since you can place it in the Activity and observe the movement of the target, as well as with the Sub-Class WebView for more detailed callback information if you need it.

0
source

Source: https://habr.com/ru/post/904387/


All Articles