0

I have this code with Loading webview, which uses the properties of Google Chrome.

The problem is that the emulator the webview loads a url containing html5 and it works perfect but on a android device using the properties of the default browser and html5 obviously does not work the url.

How i can to the webview in android device to use the properties of the Google Chrome browser and not the default browser?

Any help?

Thank you

public View onCreateView(LayoutInflater inflater, 
            ViewGroup container, Bundle savedInstanceState) {



        // Capturo las variables que dejo en memoria, nombre y email

        SharedPreferences sp1 = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
        emailAdd = sp1.getString("EMAILADDRESS", "");
        name = sp1.getString("NAME", "");

        //-----------------------------------------------


        View x = inflater.inflate(R.layout.patrocinadores, container, false);

        String url = "http://xxxx.co/xxxx/xxxx.php?email="+ emailAdd + "";


        mWebView = (WebView) x.findViewById(R.id.webView1);


        // Para colocar un loading

        pd = ProgressDialog.show(getActivity(), "", "Loading...",true);

        //--------------------------

        if(mWebView != null){

            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            mWebView.getSettings().setAppCacheEnabled(false); 
            mWebView.getSettings().setAllowFileAccess(true);
            mWebView.getSettings().setAllowContentAccess(true);



            mWebView.loadUrl(url);
            mWebView.setWebChromeClient(new WebChromeClient());

            mWebView.setWebViewClient(new WebViewClient() {



                // Coloca un loading mientras se carga el webview y se quita cuando se carga la pagina


                public void onPageFinished(WebView view, String url) {
                    if(pd.isShowing()&&pd!=null)
                    {
                        pd.dismiss();
                    }
                }

                //-----------------------------------------------


                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            });
        }

        return x;
    }

1 Answers1

0

I'm not sure I understand exactly what you're referring to, but HTML5 is supported and should work within your application if you've account for some items.

Firstly, WebChromeClient() does not refer to Google Chrome browser, but the original Chrome terminology representing the UI elements surrounding the web page (IE, buttons, scroll bars, etc.). In this sense, you can override certain default behaviors like JavaScript popup windows/notifications, titles, and other window features by implementing your own WebChromeClient() as you have done with the WebViewClient().

You can see the other definition here: https://developer.mozilla.org/en-US/docs/Glossary/Chrome

Additionally, if you are referring to scaling and layout, then I would direct you to WebView Overview, specifically Pixel-Perfect UI. For instance, setting the view port and overview mode:

mWebView.getSettings().setUseWideViewPort(true)
mWebView.getSettings().setLoadWithOverviewMode(true)

Edit:

Progress bar isn't working as expected. Try calling mWebView.loadUrl(url) after you have set the clients.

mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient(){...});
mWebView.loadUrl(url);

And override onPageStarted() within the WebViewClient():

@Override
public void onPageStarted (WebView view, String url, Bitmap favicon) {
    pd.show();
}
Taylor Frey
  • 374
  • 4
  • 6
  • ok, i understood this. The problem is that the taq who are the url displayed in the webview perfect in the emulator but in mobile android device does not display correctly. The value of progress is not shown, only the blank bar. That progress is html5 taq. –  Aug 19 '14 at 01:56
  • Ohhh. Try calling load URL after you've set the clients. – Taylor Frey Aug 19 '14 at 02:01
  • When I write the method you suggest me onPageStarted tells me this: The method onPageStarted (WebView, String) from the type new WebViewClient () {} is never used locally and if I write the @ Override tells me this: The method onPageStarted (WebView, String) of type new WebViewClient () {} must override a supertype method or in Place –  Aug 19 '14 at 02:53
  • That's probably because I had the arguments wrong in the method signature. Check out this link for the correct method signature: http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap) – Taylor Frey Aug 19 '14 at 02:57
  • Now if I'm worried, I did everything you listed but I still have the same problem: The problem is that the taq who are the url displayed in the webview perfect in the emulator but in mobile android device does not display correctly. The value of progress is not shown, only the blank bar. That progress is html5 taq –  Aug 19 '14 at 03:17