Problems with web View

0

In an android app, I have used a webView for the user to enter a "player" that consists of showing content from social networks in a presentation manner. However, it seems that this page is too "heavy" because it does not load well at all. Is there anything I can do to make this content load correctly or is there no other way to correct the problem than leaving the webView and entering the browser?

(Code used for the WebView:)

   * Método para la creación de la WebView, en la que se mostrará el enlace en el que el usuario deberá introducir el ID
     */
    public void CrearWeb ()
    {
        web=(WebView)findViewById(R.id.webV);

        //Habilitar JavaScript
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl(etiqueta);
    }

    /**
     * Método para abrir el player sin salir de la aplicación
     */
    public void Seguirweb ()
    {
        web.setWebViewClient(new WebViewClient()
        {
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        web.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event)
            {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    switch (keyCode) {
                        case KeyEvent.KEYCODE_BACK:
                            if (web.canGoBack())
                            {
                                web.goBack();
                                return true;
                            }
                            break;
                    }
                }
                return false;
            }
        });

    }

UPDATE: Comment that this problem is linked to the Android version since in versions higher than 6.0 it works correctly.

    
asked by pepito 30.06.2017 в 14:59
source

2 answers

1

Good morning,

There are two types of acceleration, software and hardware. They comment that depending on the SDK you are using, one is better than the other, and that this code speeds up the process:

if (Build.VERSION.SDK_INT >= 19) {
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}       
else {
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

Also in the activities, use this:

<application android:hardwareAccelerated="true">
    <activity ... />
    <activity android:hardwareAccelerated="false" />
</application>

The source is: Link to source

I hope I have been helpful.

    
answered by 30.06.2017 в 15:40
0

What you are saying is that it is loaded but not completely:

  

However, it seems that this page is too "heavy" because   It does not load well at all.

Which can happen because some elements or functionality of the page need javascript, the execution of javascript by default is not enabled, so you have to enable it.

myWebView.getSettings().setJavaScriptEnabled(true);

However it is important to check your LogCat, it can also happen that some resources that your page loads in the WebView, are being blocked by a proxy for example.

    
answered by 01.07.2017 в 07:10