Skip to content
Advertisement

Issue with Android Studio WebView loading certain elements on a webpage

I am using Androids WebView class to create a native application that emulates a native android application of my website.

Our website uses some pretty modern methods within the javascript and in older versions of chrome, the log in Button isnt shown and errors are thrown, even on a desktop. This can be alleviated by updating chrome to a newer/newest version.

My question is, is Chrome the browser that Android’s Webview uses? and if so is there a way to update the version of chrome within it?

(edit) I have done a good bit of research to no avail. Below is my code from my MainActivity.java from Android Studio if it helps:

package com.afi.helix;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.webkit.WebSettings;

import android.webkit.WebView;

import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

private WebView WebView;

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

    WebView = findViewById(R.id.webview);
    WebView.setWebViewClient(new WebViewClient());

    WebSettings webSettings = WebView.getSettings();
    WebView.getSettings().setJavaScriptEnabled(true);
    WebView.loadUrl("my localhost url");
}

@Override
public void onBackPressed() {
    if(WebView.canGoBack()) {
        WebView.goBack();
    } else {
        super.onBackPressed();
    }
}
}

##########################################################################

One more note: on the device I am testing on, I can load the application no problem via the chrome application, the issue is with opening it within the WebView in my android studio application

Advertisement

Answer

Is Chrome the browser that Android’s webview uses?

  • Android is controlled through Google, Google Chrome is its Browser, WebView is a light widget and no browser based on SDK but extended by external updates – Thus, NO but related.

Sidenote:

Android 4.4 KitKat first introduced a Chromium-based WebView component in 2013.


… And if so is there a way to update the version of chrome within it?

  • Through Google Play Store depending on device.

Although WebView has been based on Chromium since Android 4.4, the Chromium layer is now updatable from Google Play.

As new versions of Chromium become available, users can update from Google Play to ensure they get the latest enhancements and bug fixes for WebView, providing the latest web APIs and bug fixes for apps using WebView on Android 5.0 and higher.

I want to refer the last quote from another SO-Post posted by @Fahim.


Add to WebView in Code:

Additional Settings I would at to your WebView in MainActivity.java:

WebSettings webSettings = WebView.getSettings();
        webSettings.setSupportMultipleWindows(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setDatabaseEnabled(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setSupportZoom(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
        webSettings.setUseWideViewPort(true);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement