Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webview doesn't display web page in some cases

I have an application that's based on alfresco android sdk. After user login to the server MainActivity starts. The MainActivity has few fragments in itself. One fragment contains webview, some buttons and textview. Here is the code of xml layout:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/prop"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/video_layout"
                android:layout_width="match_parent"
                android:layout_height="192dp"          
                android:orientation="horizontal"
                android:gravity="center" >

                <WebView
                    android:id="@+id/video_web_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" /> 

            </LinearLayout>
                .
                .
                . 
        </LinearLayout>
 </ScrollView>

When the layout is displayed webview should load url of page with HTML5 video but only blank page is shown. After a while blank page changes to grey. I observed that it means page is load and it show the page with html5 video after user scroll layout. This happens with every url what I've try.

In the test activity I use the same layout and the page with video is loaded and displayed correctly.

In the fragment and in the test activity I use the same code for setting webview and loading the url. Javascript is enabled and I use WebChromeClient like is recommended in WebView docummentation. Also i have INTERNET permission in applications Manifest.

Here is the code from onCreate method from test activity :

protected void onCreate(Bundle savedInstanceState){         
        super.onCreate(savedInstanceState);     
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.web_video);
            web = (WebView)findViewById(R.id.video_web_view);
                .
                .
                .
            web.setWebChromeClient(new WebChromeClient());
            WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
            webSettings.setPluginState(PluginState.ON);
        webSettings.setDomStorageEnabled(true);
        web.setHorizontalScrollBarEnabled(false);
        web.setVerticalScrollBarEnabled(false);
        webSettings.setRenderPriority(RenderPriority.HIGH);     
        webSettings.setUseWideViewPort(false);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
            web.loadUrl(someUrl);
}

The same code contains onCreateView in fragment. Only difference is that user have to be login to the server for displaying fragment.

I almost forgotten on errors from Logcat :

02-28 09:34:20.832: V/chromium(9079): external/chromium/net/host_resolver_helper/host_resolver_helper.cc:66: [0228/093420:INFO:host_resolver_helper.cc(66)] DNSPreResolver::Init got hostprovider:0x5354b220
02-28 09:34:20.832: V/chromium(9079): external/chromium/net/base/host_resolver_impl.cc:1515: [0228/093420:INFO:host_resolver_impl.cc(1515)] HostResolverImpl::SetPreresolver preresolver:0x018ee018
02-28 09:34:21.182: V/WebRequest(9079): WebRequest::WebRequest, setPriority = 1
02-28 09:34:21.382: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:52: [0228/093421:INFO:hostres_plugin_bridge.cc(52)] StatHubCreateHostResPlugin initializing...
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:57: [0228/093421:INFO:hostres_plugin_bridge.cc(57)] StatHubCreateHostResPlugin lib loaded
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:63: [0228/093421:INFO:hostres_plugin_bridge.cc(63)] StatHubCreateHostResPlugin plugin connected
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/http/http_cache.cc:1167: [0228/093421:INFO:http_cache.cc(1167)] HttpCache::OnBackendCreated HostStat created
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:22.222: D/skia(9079): notifyPluginsOnFrameLoad not postponed

Does anyone know what i do wrong? Have anyone some suggestion taht could help me?

Thanks for your answer and sorry for my bad english.

like image 424
menda00 Avatar asked Nov 29 '25 16:11

menda00


1 Answers

So I figured out what I did wrong. It had something to do with acceleration. I simply added following line to my code:

mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

and It solved my problem.

like image 114
menda00 Avatar answered Dec 02 '25 06:12

menda00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!