-1

I'm trying to load a URL in an android WebView, which is in a Activity. I was able to accomplish this, but the website was launching the default browser. I found the setWebViewClient method and it kept the website within the WebView inside of the app versus launching the default browser. However - this was showing a blank page. I tried other websites (http://www.google.com, http://www.amazon.com, etc) and these work...however the site that I am trying to get to load (https://mizaajindia.com/) does not.

I've set javascript enabled just in case - but cannot understand why some URLs would load and others wont from within the app's WebView. Would you have any ideas?

Thanks so much!

public class MainActivity1 extends AppCompatActivity {

private MainActivity1 activity;
private ProgressDialog progDailog;
private WebView webView;

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

    setContentView(R.layout.activity_main);
    activity = this;

    progDailog = ProgressDialog.show(activity, "Loading", "Please wait...", true);
    progDailog.setCancelable(false);
    webView = (WebView) findViewById(R.id.wb_webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setWebViewClient(new WebViewClient() {

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

        @Override
        public void onPageFinished(WebView view, final String url) {
            progDailog.dismiss();
        }
    });
    webView.loadUrl("https://mizaajindia.com/");
}

}

  • 2
    Does this answer your question? [URL not loading in webview but loaded in browser in android?](https://stackoverflow.com/questions/22113651/url-not-loading-in-webview-but-loaded-in-browser-in-android) – Chaurasia Jan 25 '20 at 10:14

1 Answers1

0

for my specific case, I had to enable dom storage just like @Aaryan Negi says. this is because the site uses local storage

further information can be found in astackoverflow response and MDN's information on Web storage API

Code sample of a webview started in a fragment.


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        _binding = FragmentGuestWebViewBinding.inflate(inflater, container, false)
        val view = binding.root
        
        //declare webview domStorage
        val myWebView: WebView = binding.webView

        //enable javascript and 
        myWebView.settings.javaScriptEnabled = true
        myWebView.settings.domStorageEnabled = true

        myWebView.loadUrl("https://mixerlogic.herokuapp.com")

        // Force links and redirects to open in the WebView instead of in a browser
        myWebView.webViewClient = WebViewClient()

        return view
    }
pokumars
  • 161
  • 11