我正在使用支付网关(Voguepay),其中请求 URL 生成响应 URL,我想在 Web View 中重定向到该 URL
我的 WebView 代码
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webveiw);
mWebView = findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new MyWebViewClient());
// REMOTE RESOURCE
mWebView.loadUrl("https://voguepay.com/?p=linkToken&v_merchant_id=demo&\n" +
" memo=Payment for laptop&total=1000&merchant_ref=ref123&\n" +
" notify_url=https://example.com/notification.php&\n" +
" success_url=https://example.com/success.php&\n" +
" fail_url=https://example.com/fail.php&developer_code=ddd&cur=NGN");
}
我想重定向 webview 以加载上图中的链接
最佳答案
如果我正确理解了您的问题,您可以使用以下代码:
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
关于java - 从 android 中的 webview 获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62152149/