2

Unable to load following webpage in WebView

https://6awlanow.com/about/faqs

Tried following so far -

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setUserAgentString("Android WebView");
    webView.setWebViewClient(new WebViewClient() {

      @Override
      public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        view.loadUrl(request.getUrl().getPath());
        //if (progressDialog != null && progressDialog.isShowing()) {
        //  progressDialog.dismiss();
        //}
        return true;
      }

      //If you will not use this method url links are opeen in new brower not in webview
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
      }

      //Show loader on url load
      @Override
      public void onLoadResource(WebView view, String url) {
      }
      @Override
      public void onPageFinished(WebView view, String url) {
        try {
          //if (progressDialog.isShowing()) {
          //  progressDialog.dismiss();
          //}
        } catch (Exception exception) {
          exception.printStackTrace();
        }
      }

      @Override
      public void onReceivedError(
        WebView view, WebResourceRequest request, WebResourceError error
      ) {
        //progressDialog.dismiss();
        super.onReceivedError(view, request, error);
      }

    });

I have already provided internet permission. The URL loads fine everywhere, except on WebView. I get following error -

Get following Info on my console -

I: [INFO:CONSOLE(31)] "Uncaught TypeError: Object.assign is not a function", source: https://6awlanow.com/app.c98a13d5a9fdd32775ca.js (31)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107

2 Answers2

7

Use below code and it should work, I tested and it worked.

public class WebViewEx extends AppCompatActivity {

    private WebView webView;
    private ProgressDialog progDailog;
    Activity activity;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view_ex);

        webView = findViewById(R.id.webView);
        activity = this;

        progDailog = ProgressDialog.show(activity, "Loading", "Please wait...", true);
        progDailog.setCancelable(false);


        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                progDailog.show();
                view.loadUrl(url);

                return true;
            }

            @Override
            public void onPageFinished(WebView view, final String url) {
                progDailog.dismiss();
            }
        });

        webView.loadUrl("https://6awlanow.com/about/faqs");
    }
}

Your XML will be like below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Below is the result I got in WebView:

enter image description here

I hope this will resolve your issue and let me know if you have any query.

Pankaj Mundra
  • 1,401
  • 9
  • 25
  • That's strange, the url loaded for you is correct, however it is still not loading for me. Other URLs loading fine for me except this one still. I will create a project on GitHub with the relevant code in few hours. Please have a look at it then. – Rohan Kandwal Nov 22 '17 at 10:21
  • @RohanKandwal sure and then share the link with me, I will have a look and find out what's the issue. – Pankaj Mundra Nov 22 '17 at 10:27
  • @RohanKandwal your code is working fine on my device. The webview is opening the URL. Did you try to run your application on any other device? – Pankaj Mundra Nov 24 '17 at 04:04
  • @PankajMudra That's strange... It is working fine on some emulators but not on others, but since it is working fine on mobiles, it works for now. – Rohan Kandwal Nov 25 '17 at 13:03
1

what worked for me is

1 .Enabling dom Storage and javascript

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setDomStorageEnabled(true);

2.running webview on handler

 new Handler().post(new Runnable() {
                   @Override
                   public void run() {

                       webView.loadUrl(webview_url);

                   }
               });
  • @stdunbar May be not better but only this worked for me. Running on new handler. So i thought it might help someone. – hiren gavit Feb 17 '20 at 16:58