java - 从 android 中的 webview 获取响应

标签 java android android-webview

我正在使用支付网关(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");
}

请求 URL 加载成功并显示此内容 what it displays when it load url

我想重定向 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/

相关文章:

java - Java 中转义双引号 Oracle 准备好的语句

java - 未知变量或字段 imageURL

webview - 如何在 Xamarin.Forms 中的 Android WebView 上启用本地存储

java - 尝试在服务和另一个类之间 bundle 额外内容时出现 NullPointerException

android - 屏幕旋转后更改背景颜色无效

javascript - 在 Android WebView 中显示 Javascript 小部件

java - 如何将 map api key 存储在 local.properties 中并在 AndroidManifest.xml 中使用

java - 使用 Java Graphics2D API 在 TextLayout 中将文本右对齐

javascript - 如何在NodeJs中应用Java/Spring的分层架构?

安卓 6.0+ : No Sound Using the New MIDI API