我正在使用 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;
}
}
}