Android webview doesn't display web page in some cases
来源:互联网 发布:剑网3御姐捏脸数据 编辑:程序博客网 时间:2024/06/06 13:09
http://stackoverflow.com/questions/15133132/android-webview-doesnt-display-web-page-in-some-cases
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:0x5354b22002-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:0x018ee01802-28 09:34:21.182: V/WebRequest(9079): WebRequest::WebRequest, setPriority = 102-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 loaded02-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 connected02-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 created02-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.
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.
Check that you have included the INTERNET PERMISSION in AndroidManifest file .
<uses-permission android:name="android.permission.INTERNET" />
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.
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 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);
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!
- Android webview doesn't display web page in some cases
- some cases about "const" in C Program
- some special cases of "extern" in C
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- 问题:MySQL doesn't yet support 'LIMIT & IN/ALL/AN Y/SOME subquery
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
- Mysql:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
- Mysql:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
- Mysql:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
- MySQL报错:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME
- This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- mysql error This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- Android进程分析
- java web 中struts和spring的整合遇到的問題一
- html标签 base
- shell 脚本语法 (一)
- APP Manifest -Android
- Android webview doesn't display web page in some cases
- HTTP POST GET 本质区别详解
- http://blog.sina.com.cn/s/blog_8fbcc2dc01013yn2.html
- 木马攻击与防范
- AOJ-AHU-OJ-466 Monthly Expense
- 【类】项目三。多文件
- 概率论 基本概念
- 非root权限解决/usr/lib64/libstdc++.so.6: version过低问题
- linux 添加系统调用方法(修正)