Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.0 Webview Not Working Correctly

I developed a mobile HTML5 game which works fine when I load the URL from the web. But when I display the index.html which calls the JavaScript from the assets folder on Android 4.0 it does not work. I have included logcat and code below.

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!
like image 213
Greg Froning Avatar asked Jan 22 '26 13:01

Greg Froning


1 Answers

This is just a shot in the dark here, but it looks like your emulator requires you to call,

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

before calling,

adView.loadAd(adRequest);

Edit:

Read this and this. It looks like the Android team came to the decision that "file:///scheme" is insecure (beginning with 4.0).

Perhaps you could just upload the asset to dropbox (or somewhere online) instead and download the file at runtime.

like image 173
Alex Lockwood Avatar answered Jan 25 '26 04:01

Alex Lockwood