soma sekhar
soma sekhar

Reputation: 31

Not able reload custom URL sometimes on webviewclient

I'm using an URL in webview, when I click a link it should direct it to a custom url like paynow://xxxxx. When I use the webview client it is coming sometimes and not redirect sometime. Is there any wrong in my code. please check the url onPageStarted and shouldOverrideUrlLoading

protected void onCreate(@Nullable Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                context=this;
                MainApplication.getComponent(this).inject(this);
                back=findViewById(R.id.back_w);
                front=findViewById(R.id.right_w);
                wv1=(WebView)findViewById(R.id.webview);
                wv1.getSettings().setLoadsImagesAutomatically(true);
                wv1.getSettings().setJavaScriptEnabled(true);
               wv1.setWebViewClient(new MyBrowser());
               wv1.setWebChromeClient(new WebChromeClient());
                wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
                wv1.loadUrl(Constants.Load_url);
            }

         private class MyBrowser extends WebViewClient {


                   @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {


                        final Uri uri = request.getUrl();
                        return super.shouldOverrideUrlLoading(view, uri.toString());
                    }

                    @Override
                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
                        super.onPageStarted(view, url, favicon);

                        if (url.startsWith("paynow://"))
                        {
                            if (url.contains("order"))
                            {
                                startActivityForResult(new Intent(context,TipsActivity.class).putExtra("url",url),1);
                            }
                        }
                    }

                    @Override
                    public void onPageFinished(WebView view, String url) {
                        super.onPageFinished(view, url);

                    }

                    @Override
                    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                        super.onReceivedError(view, request, error);
                        wv1.setVisibility(View.GONE);

                    }


                }

Answer: WebView is blocking popup which redirect to custom url by adding wv1.getSettings().setPluginState(WebSettings.PluginState.ON); it worked

Upvotes: 1

Views: 76

Answers (2)

soma sekhar
soma sekhar

Reputation: 31

WebView is blocking popup which redirect to custom url, by adding wv1.getSettings().setPluginState(WebSettings.PluginState.ON); it worked

Upvotes: 0

Sander
Sander

Reputation: 816

You need to move the logic in onPageStarted to the shouldOverrideUrlLoading functions.

Upvotes: 1

Related Questions