我正在使用Android Phonegap 1.0.0我想重定向我的应用程序以在同一webview中打开所有外部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;
}
}
}
答案 0 :(得分:0)
错误消息说无法加载初始index.html,它没有说明外部链接,所以我说你没有把index.html
放在/assets/www/
目录中。
答案 1 :(得分:0)
在 super.loadUrl(“file:///android_asset/www/index.html”)之前添加以下行;
this.setIntegerProperty("loadUrlTimeoutValue", 70000);