1

I have absolutely no idea if this is the right way to do it, but i am displaying a splashscreen as long as the webview is loading, when the webview is done loading, i display the webview.

But the HTML content of the webview is not being rendered correctly. Its displaying the content correctly in the built-in browser on my Android phone, and on every other device i have. So the problem is confined to this app.

MainActivity.java

package dk.zerone.vuc;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

public final boolean networkCheck() {
    ConnectivityManager connec =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
    connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
        return true;
    } else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ) {
        return false;
    }
    return false;
}

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

    /* Splash screen */
    setContentView(R.layout.splash);

    if(networkCheck()) {

        String url = "http://mobil.vucfyn.dk/mobil";

        final WebView webview;
        webview = new WebView(MainActivity.this);
        webview.loadUrl(url);

        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //view.loadUrl(url);
                return false;
            } 

            @Override
            public void onPageFinished(WebView view, String url) { 
                super.onPageFinished(view, url); 
                setContentView(webview);

             } 
        });

    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle("Fejl");
        alertDialog.setMessage("Ingen forbindelse til internettet");

        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        alertDialog.show();
    }
  }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
    } 
}

LogCat output:

08-29 09:29:56.572: D/dalvikvm(545): GC_FOR_ALLOC freed 66K, 3% free 10191K/10503K, paused 58ms
08-29 09:29:56.579: I/dalvikvm-heap(545): Grow heap (frag case) to 11.036MB for 1048592-byte allocation
08-29 09:29:56.640: D/dalvikvm(545): GC_CONCURRENT freed 1K, 4% free 11214K/11591K, paused 4ms+4ms
08-29 09:29:56.849: I/WebView(545): webview.loadUrl(url)
08-29 09:29:57.139: D/gralloc_goldfish(545): Emulator without GPU emulation detected.
08-29 09:29:57.849: E/chromium(545): external/chromium/net/disk_cache/backend_impl.cc:1097: [0829/092957:ERROR:backend_impl.cc(1097)] Critical error found -8
08-29 09:29:58.029: W/chromium(545): external/chromium/net/disk_cache/storage_block-inl.h:119: [0829/092958:WARNING:storage_block-inl.h(119)] Failed data load.
08-29 09:29:58.029: W/chromium(545): external/chromium/net/disk_cache/storage_block-inl.h:119: [0829/092958:WARNING:storage_block-inl.h(119)] Failed data load.
08-29 09:29:58.039: W/chromium(545): external/chromium/net/disk_cache/storage_block-inl.h:119: [0829/092958:WARNING:storage_block-inl.h(119)] Failed data load.
08-29 09:29:58.059: E/chromium(545): external/chromium/net/disk_cache/entry_impl.cc:830: [0829/092958:ERROR:entry_impl.cc(830)] Failed to save user data
08-29 09:30:00.349: E/libEGL(545): call to OpenGL ES API with no current context (logged once per thread)
08-29 09:30:00.360: D/ShaderProgram(545): couldn't load the vertex shader!
08-29 09:30:00.360: E/libEGL(545): call to OpenGL ES API with no current context (logged once per thread)
08-29 09:30:00.360: D/ShaderProgram(545): couldn't load the vertex shader!
08-29 09:30:00.360: E/libEGL(545): call to OpenGL ES API with no current context (logged once per thread)
08-29 09:30:00.360: D/ShaderProgram(545): couldn't load the vertex shader!
08-29 09:30:00.360: E/libEGL(545): call to OpenGL ES API with no current context (logged once per thread)
08-29 09:30:00.360: D/ShaderProgram(545): couldn't load the vertex shader!
08-29 09:30:00.360: E/libEGL(545): call to OpenGL ES API with no current context (logged once per thread)
08-29 09:30:00.360: D/ShaderProgram(545): couldn't load the vertex shader!
user1599309
  • 101
  • 1
  • 4
  • 14
  • Any reason you using webview.loadUrl(url) twice? – Lazy Ninja Aug 29 '12 at 09:43
  • No, not really, just trying to pinpoint the problem. I have updatet the code above, i have commentet the `loadUrl(url)` in `shouldOverrideUrlLoading()` the webview is still not rendering the HTML content correctly. any help is greatly appreciated. :) – user1599309 Aug 29 '12 at 10:10

1 Answers1

3

If the website has javascript you are missing this line:

webView.getSettings().setJavaScriptEnabled(true);

And if your target is higher than 2.3.3 try adding this in your manifest file.

android:hardwareAccelerated="true"
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103