0

I have a webview on my MainActivity .. This loaded with a url set by a onclick button handling. When the webview is loaded with a certain webpage. I want to clone or duplicate (or even move) it to my secondary display/screen.

For the secondary display i have a seperate Presentation class:

private class BrowserPresentation extends Presentation {
        BrowserPresentation(Context ctxt, Display display) { super(ctxt, display); }

    WebView webView2;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            webView2=new WebView(webView.getContext()); //get webView class of mainactivity
            webView2.setWebViewClient(new WebViewClient());
            webView2.setInitialScale(100);
            setContentView(webView2);
        }

    }

However this is not working, is it even possible? Am I taking the wrong route? Can't find much on internet about secondary screen handling.

Update: I don't want to load same page, need to get current page loaded on MainActivity: Want to login on MainActivity then after the login duplicate/move it to second screen(readonly).

M.P.
  • 262
  • 1
  • 11
  • you can load same page here – Shabbir Dhangot Feb 07 '18 at 10:07
  • check with my answer - https://stackoverflow.com/questions/48594734/how-to-pass-string-url-from-main-activity-to-next-activity-and-load-url-in-webvi/48594896#48594896 – Adil Feb 07 '18 at 10:09
  • no dont load same page, need to get current page, want to login on main screen then after the login duplicate it to second screen. On that screen it is read only – M.P. Feb 07 '18 at 10:11

1 Answers1

0
As per Android dev page :
Handling Page Navigation
When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView. You can then allow the user to navigate backward and forward through their web page history that's maintained by your WebView.

To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient(). For example:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
That's it. Now all links the user clicks load in your WebView.

If you want more control over where a clicked link load, create your own WebViewClient that overrides the shouldOverrideUrlLoading() method. For example:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.example.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}
Then create an instance of this new WebViewClient for the WebView:


  [1]: https://developer.android.com/guide/webapps/webview.html
Chetan Ansel
  • 398
  • 2
  • 20