我开发了一个移动 HTML5 游戏,当我从 Web 加载 URL 时它运行良好。但是,当我在 Android 4.0 上显示从 assets 文件夹中调用 JavaScript 的 index.html 时,它不起作用。我在下面包含了 logcat 和代码。
public class BlockyBlaine extends Activity {
WebView webview;
AdView adView;
private class BlaineViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = (AdView) findViewById(R.id.adView);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.getSettings().setSupportZoom(false);
webview.setVerticalScrollBarEnabled(false);
webview.setHorizontalScrollBarEnabled(false);
webview.getSettings().setUseWideViewPort(false);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl("file:///android_asset/www/index.html");
webview.setWebViewClient(new BlaineViewClient());
webview.setFocusableInTouchMode(false);
adView.loadAd(new AdRequest());
}
}
06-09 19:06:06.275: I/Ads(1342): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
06-09 19:06:06.675: I/Ads(1342): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"8885582241455077410","u_sd":1.5,"seq_num":"1","slotname":"a14fd0f1400116b","u_w":320,"msid":"com.blockyblaine.bobhoil","simulator":1,"cap":"m,a","js":"afma-sdk-a-v6.0.1","isu":"B3EEABB8EE11C2BE770B684D95219ECB","cipa":0,"format":"320x50_mb","net":"ed","app_name":"1.android.com.blockyblaine.bobhoil","hl":"en","u_h":533,"carrier":"310260","ptime":0,"u_audio":4});</script></head><body></body></html>
06-09 19:06:06.715: D/gralloc_goldfish(1342): Emulator without GPU emulation detected.
06-09 19:06:06.765: D/dalvikvm(1342): GC_CONCURRENT freed 220K, 4% free 10110K/10439K, paused 5ms+7ms
06-09 19:06:07.375: D/chromium(1342): Unknown chromium error: -6
06-09 19:06:07.515: E/libEGL(1342): call to OpenGL ES API with no current context (logged once per thread)
06-09 19:06:07.515: D/ShaderProgram(1342): couldn't load the vertex shader!
06-09 19:06:07.525: E/libEGL(1342): call to OpenGL ES API with no current context (logged once per thread)
06-09 19:06:07.525: D/ShaderProgram(1342): couldn't load the vertex shader!
06-09 19:06:07.525: E/libEGL(1342): call to OpenGL ES API with no current context (logged once per thread)
06-09 19:06:07.535: D/ShaderProgram(1342): couldn't load the vertex shader!
06-09 19:06:07.535: E/libEGL(1342): call to OpenGL ES API with no current context (logged once per thread)
06-09 19:06:07.535: D/ShaderProgram(1342): couldn't load the vertex shader!
06-09 19:06:07.545: E/libEGL(1342): call to OpenGL ES API with no current context (logged once per thread)
06-09 19:06:07.555: D/ShaderProgram(1342): couldn't load the vertex shader!