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

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

问题描述

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

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

我有回调可正常工作if我通过

I have the callback working properly if I open the 3rd party site in a separate browser process via

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

但是,如果我在我的布局中嵌入一个WebView组件,并打开url,不工作。 Webview说你没有权限打开myapp:// callback?token = ....并快速刷新为网页不可用...暂时下来... blah blah

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之前拦截自定义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)以检查该网址是否为您的自定义网址,并根据需要处理。

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天全站免登陆