我正在我的Android应用程序中实现Citrus的paymentGateway。我在控制台中遇到错误。
12-22 17:13:03.041:I / chromium(13772):[INFO:CONSOLE(12)]“Uncaught” ReferenceError:paymentResponse未定义“,
来源:http://www.palamsilk.com/Webservice/PayResponseIOS.aspx(12)
以下是我的Webview代码:
private WebView loadwebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.netpayscreen);
initScreen();
String url = getIntent().getStringExtra("URL");
startWebView(url);
}
private void initScreen() {
// TODO Auto-generated method stub
loadwebview = (WebView) findViewById(R.id.webView1);
}
private void startWebView(String url) {
// Create new webview Client to show progress dialog
// When opening a url or click on link
loadwebview.setWebViewClient(new WebViewClient() {
ProgressDialog progressDialog;
// @Override
// public void onPageStarted(WebView view, String url, Bitmap
// favicon) {
// super.onPageStarted(view, url, favicon);
//
// if (progressDialog == null) {
// // in standard case YourActivity.this
// progressDialog = new ProgressDialog(NetPayActivity.this);
// progressDialog.setMessage("Loading...");
// progressDialog.show();
// }
// }
// If you will not use this method url links are opeen in new brower
// not in webview
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
// Show loader on url load
public void onLoadResource(WebView view, String url) {
if (progressDialog == null) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(NetPayActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
try {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
try {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
loadwebview.loadUrl(url);
loadwebview.getSettings().setJavaScriptEnabled(true);
loadwebview.addJavascriptInterface(new JavaScriptInterface(this),
"Android");
// Javascript inabled on webview
// Load url in webview
}
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
public void paymentResponse(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
付款成功后,我的paymentResponse函数永远不会被调用。
答案 0 :(得分:0)
您错过了注释@JavascriptInterface for function paymentResponse