【发布时间】:2021-05-11 22:14:57
【问题描述】:
我创建了 HTML 支付表单并在本地添加到 android studio,它完美地加载到了 Webview 我的问题是当我按下付款表单中的按钮时无法进行交易
这是我的代码
web = findViewById(R.id.payment);
loadHtmlPage(web);
web.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// Here put your code to exit
Log.i("Payment","The Request is "+'\n'+ request);
return true;
}
});
}
/**
* Loads html page with the content.
*/
private void loadHtmlPage(WebView mweb){
String htmlString = getHtmlFromAsset();
if (htmlString != null) {
htmlString = htmlString.replace("$AMOUNT$",amount);
mweb.loadDataWithBaseURL(" ", htmlString, "text/html", "UTF-8", null);
} else
Toast.makeText(this, "no such page", Toast.LENGTH_LONG).show();
}
private String getHtmlFromAsset () {
InputStream is;
StringBuilder builder = new StringBuilder();
String htmlString = null;
try {
is = getAssets().open("payment.html");
if (is != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
htmlString = builder.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return htmlString;
}
【问题讨论】:
标签: android webview payment-gateway