2013-08-01 39 views
10

Tôi đang thử một ứng dụng đơn giản, nơi tôi muốn hiển thị trang web di động của mình bên trong trình bao bọc gốc trong Android. Tôi đang theo dõi tài liệu mà thay đổi duy nhất tôi đang thực hiện là với loadUrl, thay vì tải CordovaWebView bằng index.html từ thư mục nội dung, tôi sẽ trỏ đến trang web trên thiết bị di động, nói https://www.google.comCordova WebView TIMEOUT ERROR với android

Ứng dụng webview xuất hiện nhưng không có một CordovaWebView TIMEOUT ERROR nhận được. Sau đây là các đoạn từ mã của tôi

public class CordovaWebViewActivity extends Activity implements CordovaInterface{ 

    private CordovaWebView webView; 
    private static final String TAG = "CORDOVA_WEBVIEW_ACTIVITY"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_cordova_web_view); 

     webView = (CordovaWebView)findViewById(R.id.webview); 
     webView.loadUrl("https://www.google.com"); 


    } 

    @Override 
    public Activity getActivity() { 
    return this; 
    } 
    //... other overrided methods from interface 
} 

và khi tôi chạy mã, tôi nhận được lỗi sau trong giao diện điều khiển của tôi DDMS

07-31 20:56:08.737: D/dalvikvm(2016): GC_FOR_ALLOC freed 42K, 6% free 2780K/2928K, paused 23ms, total 25ms 
07-31 20:56:08.746: I/dalvikvm-heap(2016): Grow heap (frag case) to 3.887MB for 1127536-byte allocation 
07-31 20:56:08.777: D/dalvikvm(2016): GC_FOR_ALLOC freed 2K, 4% free 3879K/4032K, paused 36ms, total 36ms 
07-31 20:56:08.836: D/CordovaWebView(2016): CordovaWebView is running on device made by: unknown 
07-31 20:56:08.836: D/JsMessageQueue(2016): Set native->JS mode to 2 
07-31 20:56:08.996: D/gralloc_goldfish(2016): Emulator without GPU emulation detected. 
07-31 20:56:09.376: E/cutils-trace(2016): Error opening trace file: No such file or directory (2) 
07-31 20:56:09.687: D/TilesManager(2016): Starting TG #0, 0x2a26cc40 
07-31 20:56:28.874: E/CordovaWebView(2016): CordovaWebView: TIMEOUT ERROR! 

Tôi có config.xml trong thư mục/res/xml của tôi rằng có thư mục sau

<?xml version='1.0' encoding='utf-8'?> 
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets"> 
    <name>Hello Cordova</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="index.html" /> 
    <feature name="App"> 
     <param name="android-package" value="org.apache.cordova.App" /> 
    </feature> 
    <access origin="*" /> 
    <preference name="useBrowserHistory" value="true" /> 
    <preference name="exit-on-suspend" value="false" /> 
    <preference name="fullscreen" value="true" /> 
    <preference name="webviewbounce" value="true" /> 
</widget> 

và tôi cũng có một cordova.xml trong tôi/res/xml

<?xml version="1.0" encoding="utf-8"?> 

<cordova> 

    <access origin="http://127.0.0.1*"/> <!-- allow local pages --> 
    <access origin="https://www.google.com" /> 


    <log level="DEBUG"/> 
    <preference name="useBrowserHistory" value="false" /> 
</cordova> 

Xin vui lòng giúp đỡ những gì tôi bị thiếu hoặc làm sai?

+0

bạn đã tìm thấy giải pháp chưa. Tôi phải đối mặt với cùng một vấn đề. xin vui lòng chia sẻ –

Trả lời

13

Bạn không làm gì sai, TIMEOUT ERROR có thể xảy ra vì điện thoại Android của bạn (hoặc trình giả lập) chạy quá chậm.

Bạn có thể cố gắng tăng thời gian chờ tải với các hướng dẫn sau đây:

super.setIntegerProperty("loadUrlTimeoutValue", 60000); 

trong phương pháp OnCreate của bạn. Hoặc đặt nó trong tệp config.xml:

<preference name="loadUrlTimeoutValue" value="60000" /> 
+0

vì vậy, tôi có cùng một lỗi, tôi có nghĩa là gần như giống nhau. Tôi có tải trang web với tất cả nội dung, nhưng sau một thời gian sau, tôi có L TIMEI THỜI GIAN này đến. Với sửa đổi của bạn, nó đã trở nên tốt hơn nhưng đã không đi. Bạn có thể cho tôi biết lý do tại sao điều này hạnh phúc chút nào, ngay cả sau khi tải trang thành công? – Karoly