java - 从android中的webview获取响应
问题描述
我正在使用支付网关(Voguepay),其中请求 URL 生成响应 URL 我想在 webview 中重定向到该 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
}
});
推荐阅读
- flutter - Flutter getx无限滚动刷新listview每次结束滚动
- html - 新标签中的角度显示图像
- windows - Visual Studio:删除“我的代码片段”文件夹是否安全?
- java - 使用 JUnit 5 的并发 Spring Boot 测试正在启动多个 JVM
- r - 从闪亮的事件反应生成数据框
- java - 尝试实现 dijkstra 的算法(在我无法完全修复的线程中遇到异常)
- c - 在显示之前将数据传递给 Glade UI
- c++ - 我应该只向构造函数和移动运算符编写 noexcept 吗?
- angular - 为什么在具有 formGroup.errors 时没有 mat-error 的 Angular 表单有效?
- json - Angular 8 - 创建从 POST 请求返回的 JSON 键/值列表