http://stackoverflow.com/questions/15133132/android-webview-doesnt-display-web-page-in-some-cases

Android webview doesn't display web page in some cases

up vote 1 down vote favorite

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.

android android-webview html5-video
share | improve this question asked Feb 28 '13 at 10:28 menda00
31 1 4
add comment

5 Answers

active oldest votes
up vote 2 down vote

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 answered Mar 14 '13 at 12:32 menda00
31 1 4
add comment
up vote 0 down vote

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

 <uses-permission android:name="android.permission.INTERNET" />
share | improve this answer answered Feb 28 '13 at 10:34 Asteriskiiii
231 2 11
Thanks for your answer but I alredy have this permission in Manifest file.– menda00 Feb 28 '13 at 14:25
add comment
up vote 0 down vote

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 answered Feb 28 '13 at 12:49 AndroidEnthusiastic
499 4 15
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 triedView.isHardwareAccelerated()and the method returnsfalsein both cases. Even if I haveandroid:hardwareAccelerated="true"in my Manifest. So I tried everything from thislinkand it still returnsfalse.– menda00 Feb 28 '13 at 15:15
add comment
up vote 0 down vote

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 answered Nov 12 '13 at 6:05 Chasel Lee
11 1
add comment
up vote 0 down vote

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 beexactlyright 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!

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android MediaController
  2. 通过JS或PHP检测Android
  3. Android在设置里面添加新功能的方法
  4. 关于android:focusable属性
  5. [AndroidTips]Android预定义样式
  6. 基于百度地图API的Android公交换乘导航
  7. Android API Level对应Android版本一览表
  8. Unable to resolve target 'android-5'
  9. USB UMS MTP设置过程 (二) UsbDeviceManage
  10. Android(安卓)Launcher研究