3 Replies - 969 Views - Last Post: 07 March 2019 - 04:50 PM

#1 justawebuser   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 09-February 14

B4A - webview using chrome browser

Posted 27 July 2017 - 10:57 PM

Hello everybody
In the WebView that is based on default browser of android my website doesn't load correctly, How can I load it using chrome at least in the case that chrome is installed? Note that I don't want execute chrome browser I want to embed it inside of the application layout. Any ideas?
Thanks in advance,
Is This A Good Question/Topic? 1
  • +

Replies To: B4A - webview using chrome browser

#2 justawebuser   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 09-February 14

Re: B4A - webview using chrome browser

Posted 23 February 2019 - 05:15 AM

AFYI , From version 4.4 , chrome is the default core used by webviews , I thought it may be useful to know
Was This Post Helpful? 0
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: B4A - webview using chrome browser

Posted 25 February 2019 - 12:22 PM

Android should use Chromium regardless of what you do but one option would be to use WebChromeClient instead of WebViewClient.

from stack: https://stackoverflo...webchromeclient

private volatile WebChromeClient mWebChromeClient;

public void setWebChromeClient(WebChromeClient client) {
    mWebChromeClient = client;


Did you enable javascript in your WebView and have you created your webpage with both a mobile and desktop version? What exactly is not displayed correctly?
Was This Post Helpful? 0
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: B4A - webview using chrome browser

Posted 07 March 2019 - 04:50 PM

So that explanation that I gave you before was kinda flimsey and I'd like to revise it a bit, here's how you can set the WebChromeClient .. I am using Xamarin C# but the syntax for Android studio Java is very similar if not identical.

Here's an example of one inside OnCreateView

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.TheFragmentLayout2, container, false);

            WebView _wv = view.FindViewById<WebView>(Resource.Id.webView66);

            _wv.SetWebChromeClient(new WebChromeClient());

            _wv.LoadUrl("https://www.google.com/");

            WebSettings webSettings = _wv.Settings;

            webSettings.JavascriptEnabled = true;

            return view;
         }

            


Attached Image

versus

_wv.SetWebViewClient(new WebViewClient());

Attached Image

Note that you can also implement functions like this, which allow the user of an android app to select files through WebView .. just using this for illustrative purposes:

(this is java though, not C#.. note the { } )

mWebView.setWebChromeClient(new WebChromeClient()
{
    // For 3.0+ Devices (Start)
    // onActivityResult attached before constructor
    protected void openFileChooser(ValueCallback uploadMsg, String acceptType)
    {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("image/*");
        startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
    }


    // For Lollipop 5.0+ Devices
    public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
    {
        if (uploadMessage != null) {
            uploadMessage.onReceiveValue(null);
            uploadMessage = null;
        }

        uploadMessage = filePathCallback;

        Intent intent = fileChooserParams.createIntent();
        try
        {
            startActivityForResult(intent, REQUEST_SELECT_FILE);
        } catch (ActivityNotFoundException e)
        {
            uploadMessage = null;
            Toast.makeText(getActivity().getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }

    //For Android 4.1 only
    protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
    {
        mUploadMessage = uploadMsg;
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);
    }

    protected void openFileChooser(ValueCallback<Uri> uploadMsg)
    {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("image/*");
        startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
    }
});


EDIT: when I say "the syntax is similar" .. I am referring to only the SetWebChromeClient line of code.

This post has been edited by hexagod: 07 March 2019 - 07:56 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1