Android:WebView 组件的回调? [英] Android: Callbacks with WebView component?

查看:22
本文介绍了Android:WebView 组件的回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方站点进行身份验证,该站点应该使用身份验证令牌 (OAUTH) 重定向回我的应用.

I am doing authentication with a third-party site that's supposed to redirect back to my app with auth token (OAUTH).

如果我通过

this.startActivity(new Intent(Intent.ACTION_VIEW, uri));

但是,如果我在布局中嵌入一个 WebView 组件,并在其中打开 url,则回调不起作用.Webview 显示您无权打开 myapp://callback?token=...."并快速刷新为网页不可用...暂时关闭...等等"

but, if I embed a WebView component in my layout, and open the url in that, the callback does not work. Webview says "You do not have permission to open myapp://callback?token=...." and quickly refreshes to "Web page not available...temporarily down...blah blah"

有什么想法吗?

推荐答案

你需要实现一个 WebViewClient 在加载之前拦截自定义 URI.Hello, WebView 教程 展示了一个简单的示例.他们有:

You need to implement a WebViewClient to intercept the custom URI before it is loaded. The Hello, WebView tutorial shows a simple example. Where they have:

private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

您可以更改view.loadUrl(url)"以检查该 URL 是否是您的自定义 URL 并根据需要进行处理.

You can change "view.loadUrl(url)" to check if the URL is your custom URL and handle it however you want.

这篇关于Android:WebView 组件的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆