0

I'm about to roll out an app for my cricket team where we can view or match videos... However, there are some ads in the webview, if clicked on the ad, it loads in that same webview so the video is lost. How can I implement a code that opens the ad in the android browser instead of app webview??

.java File

WebView displayVideo = findViewById(R.id.webView); displayVideo.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon){
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
            setTitle("Loading...");
        }
        @Override
        public void onPageFinished(WebView view, String url){
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            setTitle(view.getTitle());
            view.loadUrl("javascript:onPageFinished();");

        }




    });
    WebSettings webSettings = displayVideo.getSettings();
    webSettings.setJavaScriptEnabled(true);
    displayVideo.loadData(frameVideo, "text/html", "utf-8");
    webSettings.setMediaPlaybackRequiresUserGesture(false);


}
Kezxi
  • 63
  • 6

1 Answers1

0

You can intercept URL loading by

    @Override
       public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
           Uri url = request.getUrl();
           // checking your url pattern
     return super.shouldOverrideUrlLoading(view, request);
     }

And if url is ad's url. You can open browser by Intent -> Sending an Intent to browser to open specific URL

JingJoeh
  • 393
  • 4
  • 14
  • Thanks for your reply.... Do you have any clue on how to block multiple URLs from loading? By placing a text file with all the urls in the assets folder? I'm not sure on how to implement such code to have this done... – Kezxi May 25 '18 at 19:05