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.

share | improve this question
  add comment

5 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.

share | improve this answer
  add comment

Check that you have included the INTERNET PERMISSION in AndroidManifest file .

     <uses-permission android:name="android.permission.INTERNET" />
share | improve this answer
 
 
Thanks for your answer but I alredy have this permission in Manifest file. –   menda00  Feb 28 '13 at 14:25
add comment

please add

android:hardwareAccelerated="true"

in your webview activity class file. because in android 3.0+ its supports only if we add this line in android manifest file.

share | improve this answer
 
 
I read about this befor and add this line to Manifest but it doesn't help. –   menda00  Feb 28 '13 at 14:28
 
I had to think about your answer again and I tried View.isHardwareAccelerated() and the method returns false in both cases. Even if I have android:hardwareAccelerated="true" in my Manifest. So I tried everything from this link and it still returns false. –   menda00  Feb 28 '13 at 15:15 
add comment

I had the same problem. below code segment solved the problem

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);     
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);   
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl(url);
share | improve this answer
  add comment

After looking at this post and doing some other research I finally figured out what my issue was. My manifest was right, my layout and webview setup was all correct. However, the URL that I was passing into my WebViewActivity class was not formatted correctly. The difference is very subtle...

I had my URL formatted a certain way:

FORMAT: "scheme://www.websitename.com//"

EXAMPLE: "http://www.awebsite.com//"

It turns out however some websites are not formatted exactly this way and the job of a browser is to fill in the blanks for you. For instance, you can just type "google.com" into a browser and it will know to take you to "https://www.google.com/". The Android WebView does not do this.

The fix: Visit the website that you are trying to load in a desktop browser and copy the URL after the website loads.

Paste it directly into your Java code:

final String websiteURL = "http://awebsite.com//";

Note that there is no "www." on this URL. Some websites require "www." and some do not. Again, copy the URL from your desktop web browser to determine whether or not the "www." is needed. Another thing to note is that on the end of this URL there is a double-slash "//".

Bottom line, the Android WebView is finicky and it requires that the string URL be exactly right or it will start tossing up errors like this one:

12-16 13:40:26.518: E/chromium(13869): external/chromium/net/disk_cache/stat_hub.cc:216: [1216/134026:ERROR:stat_hub.cc(216)] StatHub::Init - App com.nucitrus.thestory isn't supported.

I hope this helps!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值