Cordova WebView在Android上出现超时错误

14

我正在尝试一个简单的应用程序,在其中我想在Android的本地包装器中显示我的移动网站。我正在遵循文档,唯一改变的是loadUrl的位置,不是从资产文件夹中加载index.html,而是指向一个移动网站,比如https://www.google.com

Webview应用程序启动,但是收到了CordovaWebView TIMEOUT ERROR。以下是我的代码片段:

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
}

当我运行代码时,在我的控制台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!

我在/res/xml文件夹中有一个config.xml,其内容如下:

<?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="dev@cordova.apache.org" 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>

我在/res/xml文件夹中也有一个cordova.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>

请帮忙我到底缺了什么或者做错了什么?


你找到解决方案了吗?我也遇到了同样的问题,请分享。 - Qadir Hussain
2个回答

21

你没有做错任何事情,TIMEOUT ERROR 可能是因为你的安卓手机(或者模拟器)运行得太慢了。

你可以尝试按照以下指示增加加载超时时间:

super.setIntegerProperty("loadUrlTimeoutValue", 60000);

在您的OnCreate方法中设置。或在config.xml文件中进行设置:

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

所以,我有相同的错误,几乎是一样的。我的网站加载了所有内容,但是过了一段时间后,就会出现“超时错误”。尽管你的修改使情况有所改善,但问题仍然存在。你能告诉我为什么会发生这种情况吗?即使页面成功加载后? - narancs
好的,现在我的应用程序已经加载了,但是加载过程非常漫长。我该如何找到原因? - Boris Gappov

-1

正确答案是

<preference name="LoadUrlTimeoutValue" value="60000"/> - capital 'L'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接