Adi
Adi

Reputation: 921

Android application is stuck on links in Android Webview

Background

I am making an app which uses Quora links All Links(profiles,answers,topics,except sign in) are Opening in My App only .

Problem

In both cases the app is stuck .I tried WebView Client Solution that is working fine but for sign in case it is not working.

enter image description here

Upvotes: 0

Views: 658

Answers (1)

mdtuyen
mdtuyen

Reputation: 4548

There are two require that you need:

  • Hide element of website (here is "Open in App" button)
  • Disable event of element in website (here is signin click)

and solution you can found at WebViewClient class:

webview.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(!url.equals(currentUrl)){ //currentUrl is url that signin with navigated.
            view.loadUrl(url);  
        }
        return true;
    }
    @Override
    public void onPageFinished(WebView view, String url)
    {
        // hide element by class name
        webview.loadUrl("javascript:(function() { " +
                "document.getElementsByClassName('your_class_name')[0].style.display='none'; })()");
        // hide element by id
        webview.loadUrl("javascript:(function() { " +
                "document.getElementById('your_id')[0].style.display='none';})()");

    }
});

Upvotes: 1

Related Questions