android - 在 phonegap 中与服务器的连接失败

标签 android cordova android-intent

我正在使用 phonegap,当我尝试加载 html 文件时出现此错误

The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

我的代码:

import org.apache.cordova.DroidGap;

import android.os.Bundle;

import android.view.Menu;

public class LoadHtml extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        super.setIntegerProperty("loadUrlTimeoutValue", 60000);
        super.loadUrl("file:///android_asset/www/index5.html");


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_first, menu);
        return true;
    }
}

最佳答案

问题可能是由于模拟器或设备的速度,网络太慢无法在默认时间内完成通信。

在调用super.loadUrl("file:///android_asset/www/index.html");之前使用super.setIntegerProperty("loadUrlTimeoutValue", 60000);>

它设置了 60 秒的超时时间来完成通信。

它对我有用。

关于android - 在 phonegap 中与服务器的连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13177211/

相关文章:

android - 如何将 "Action Bar Icon Pack"添加到 Android Studio

android - 有没有办法使用 Android 中的 DownloadManager 通过 LAN 下载?

ios - 在原生 ios 代码和 html 之间切换(phonegap)

javascript - 如何从 Sencha Touch/Phonegap 应用程序的虚拟键盘中删除 Next 和 Prev 按钮

android - 如何使用 achartengine 在 fragment 中膨胀 Intent

android - 如何从 Android 的 SD 卡中读取文本文件?

android - 在 RetrofitError 中捕获错误并将其传递给 RoboSpice Error

javascript - 如何在 Ionic 中从另一个文件添加模板?

java - 如何将 Uri 图像从一个 Activity 传输到另一个 Activity ?

android - 如何在最近的应用程序中显示一个应用程序的 2 个不同 Activity ?