0

我正在使用 Android Phonegap 1.0.0 我想重定向我的应用程序以在同一个 web 视图中打开所有外部 URL。我尝试了以下但它给出了错误。

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

我哪里出错了?

我的代码:

package com.phonegap.phonegapsample;
import com.phonegap.*;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PhonegapSampleActivity extends DroidGap {

private WebView myWebView;
private WebSettings myWebSetting;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState); 

    super.loadUrl("file:///android_asset/www/index.html");

    //Get the Webview
    myWebView = super.appView; 

    //Get the WebSettings
    myWebSetting = myWebView.getSettings();

    //Enable Javascript 
    myWebSetting.setJavaScriptEnabled(true);

    //Enable Zoom default : disabled
    myWebSetting.setBuiltInZoomControls(true);
    myWebSetting.setSupportZoom(true);              

    //myWebSetting.setDefaultZoom(ZoomDensity.FAR);
    //myWebSetting.setUseWideViewPort(true);
    //myWebSetting.setLoadWithOverviewMode(true);

    myWebView.setWebViewClient(new MyWebViewClient());

}

private class MyWebViewClient extends WebViewClient{

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.loadUrl(url);
        return true;
    }

} 

}
4

2 回答 2

0

错误消息说无法加载初始 index.html,它没有说明外部链接,所以我会说你没有放入index.html目录/assets/www/

于 2012-08-09T10:36:42.600 回答
0

在super.loadUrl("file:///android_asset/www/index.html");之前添加以下行

this.setIntegerProperty("loadUrlTimeoutValue", 70000);
于 2012-08-09T10:50:52.337 回答