我有一個基於alfresco android sdk的應用程序。用戶登錄到MainActivity服務器後啓動。 MainActivity本身幾乎沒有片段。一個片段包含webview,一些按鈕和textview。以下是XML佈局的代碼:Android webview在某些情況下不顯示網頁
<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>
當佈局顯示的WebView應該加載頁面的URL與HTML5視頻,但只顯示空白頁。過了一會兒,空白頁面變爲灰色。我觀察到,這意味着頁面加載,並且在用戶滾動佈局之後,它顯示帶有html5視頻的頁面。這發生在我試過的每個網址上。
在測試活動中,我使用相同的佈局,帶有視頻的頁面被正確加載和顯示。
在片段和測試活動中,我使用相同的代碼來設置webview並加載url。 Javascript已啓用,並且我使用WebChromeClient就像在WebView文檔中推薦的一樣。此外,我在應用程序清單中擁有INTERNET權限。
下面是從onCreate方法的代碼從測試活動:
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);
}
相同的代碼包含在onCreateView片段。唯一不同的是用戶必須登錄到服務器以顯示片段。
我幾乎忘記了對錯誤的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
有誰知道我做錯了什麼?有沒有人有一些建議可以幫助我?
感謝您的回答,並對我的英文不好。
感謝您的回答,但我alredy在清單文件中有這種權限。 – menda00 2013-02-28 14:25:03