我正在尝试以下面提到的方式使用 CordovaWebView public class TechTimeMainActivity extends DroidGap implements CordovaInterface{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
CordovaWebView webview = new CordovaWebView(this);
webview.setWebViewClient(new CordovaWebViewClient(this, webview) {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i(TAG,"Overridden URL Outside IF-->"+ url);
if(url.contains("OGTE"))
{
String cookie = CookieManager.getInstance().getCookie(url);
Log.i(TAG,"Cookie for new url-->"+ cookie);
Log.i(TAG,"Overridden URL Inside IF-->"+ url);
view.clearSslPreferences();
view.loadUrl("file:///android_asset/www/index.html");
return true;
}
return true;
}
@Override
public void onPageFinished(WebView view, String url)
{
Log.i(TAG,"Finished Loading-->"+ url);
CookieSyncManager.getInstance().sync();
// Get the cookie from cookie jar.
String cookie = CookieManager.getInstance().getCookie(url);
if (cookie == null) {
return;
}
Log.i(TAG,"Cookie-->"+cookie);
}
});
webview.setWebChromeClient(new CordovaChromeClient(this) {
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
}
@Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(myApp)
.setTitle("javaScript dialog")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.confirm();
}
})
.setCancelable(false)
.create()
.show();
return true;
};
});
setContentView(webview);
webview.loadUrlIntoView("file:///android_asset/www/index2.html");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_tech_time_main, menu);
return true;
}
}
问题是如果我使用 super.loadUrl() 调用我的 loadurl 方法,我的 phonegap API 可以正常工作。但是如果我以上述方式调用我的 CordovaWebView,我的 phonegap api 将无法正常工作。对此的任何帮助都将非常有用。