我试图以下面提到的方式使用CordovaWebView 公共类TechTimeMainActivity扩展DroidGap实现了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 apis无效。任何有关这方面的帮助都将非常有用。