1

I have a list of web urls. I need to open them all at once in an external browser where each link's page results in a new tab. So for example, if the list has a link to google.com and yahoo.com they should both be opened in the browser in their own separate tabs.

To open a single link within an external browser is pretty straight forward - create an ACTION_VIEW intent, set the url and call startActivity. But how can I do this with multiple urls? Doing multiple startActivity calls won't work. Any ideas?

Thank you for your time!

Klarre
  • 107
  • 9

1 Answers1

0

My answer is based on a little research so I am not sure about the exact code but I will suggest an approach here

First you can have a Fragment or Activity with the WebView view type in the layout file respectively and depending on your use case, get the reference for the WebView. We will pass your list of urls to the activity containing the Webview

Say, we do it like so

val arrayList = getIntent().getArrayListExtra("urls")
val webView = findViewById<WebView>(R.id.myWebview)

Now we can listen to scroll changes of the WebView and wait for the user to reach the end of the WebView page as given in the following link

How to check the scrollend of WebView

And then when the scroll end is reached, we can load the next url from the array

webView.setOnScrollChangeListener((view, i, i1, i2, i3) -> {
            int r1 = webView.computeVerticalScrollRange();
            int r2 = webView.computeVerticalScrollExtent();
            if (i1 == (r1 - r2)) {
                webView.loadUrl(arrayList.get(1) // Or Whatever your next 
                index is
             // Maybe maintain a global variable for which url is currently 
            loaded
            } 
        });

To make the experience nice for the user you can consider setting a WebViewClient for your WebView and override onProgressChanged to show the progress to the user, just in case he doesn't feel lost

gtxtreme
  • 1,830
  • 1
  • 13
  • 25
  • Let me know, if this works for you, I just had an idea in my head and then worked out a solution through some research for you – gtxtreme Sep 16 '21 at 16:37
  • "in an external browser" seems to imply that the OP isn't using a WebView – Code-Apprentice Sep 16 '21 at 16:49
  • 1
    @Code-Apprentice you're right, but I don't think of anyway by which we can have some control over the external browsers other than just requesting them to open url. So a `WebView` will always be preferred to have the functionality of the browser as well as customisation – gtxtreme Sep 16 '21 at 16:58
  • Yes, that's right, there is no webview. They should be opened in the default browser, so the solution must be simple and general so it works in many browsers. – Klarre Sep 16 '21 at 17:00
  • Alright so should I delete this answer then? – gtxtreme Sep 16 '21 at 17:02