安卓:回调与web视图组件? [英] Android: Callbacks with WebView component?

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

问题描述

我做验证了这是应该重定向到我的应用程序与身份验证令牌(OAUTH)第三方网站。

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

我有回调的正常工作,如果我通过

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://回调令牌= ​​...并迅速刷新,找不到网页......暂时关闭......等等等等

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。 的你好,的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.

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

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