1

我完全不知道这是否是正确的方法,但是只要 webview 正在加载,我就会显示启动画面,当 webview 完成加载时,我会显示 webview。

但是 webview 的 HTML 内容没有正确呈现。它在我的 Android 手机以及我拥有的所有其他设备上的内置浏览器中正确显示内容。所以问题仅限于这个应用程序。

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 输出:

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!
4

1 回答 1

3

如果该网站有 javascript,则您缺少此行:

webView.getSettings().setJavaScriptEnabled(true);

如果您的目标高于 2.3.3,请尝试将其添加到清单文件中。

android:hardwareAccelerated="true"
于 2012-08-29T10:14:53.883 回答