的WebView URL过滤的Andr​​oid [英] WebView URL Filtering Android

查看:246
本文介绍了的WebView URL过滤的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:我有一个web视图。我加载在它的HTML文件。有在该HTML一个按钮。

What I have: I have a WebView. I am loading an HTML file in it. There is a button in that HTML.

我要什么:我想拦截HTML按钮的点击。可以说存在这样的URL的电子邮件方案。我想拦截请求,这样我可以提取电子邮件信息(即主题,正文等)和实际加载页面之前打开一个电子邮件客户端。

What I want: I want to intercept the click of that HTML button. Lets say there is an email scheme in that URL. I want to intercept the request so that I can extract the email information (i.e. Subject, Body etc) and open an Email Client before loading the page actually.

什么问题:我想不出如何获取URL和过滤它的HTML按钮的点击。应该有,每当我们做的WebView功能的任何请求应被解雇的事件。请指导如何实现这一任务。

What is the problem: I can't figure out on how to get the URL and filter it on HTML button click. There should be an event which should be fired whenever we make any request from WebView. Please guide on how to achieve this task.

推荐答案

首先,你所使用的HTML,你应该检查Java脚本是否已启用

First of all as you are using html, you should check whether java script is enabled or not

myWebView.getSettings().setJavaScriptEnabled(true);

其次,你可以使用

secondly you can use

myWebView.setWebViewClient(new WebViewClient()
  {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

当你点击一个链接它会带你到这个功能shouldOverrideUrlLoading在那里你可以调用意图或做任何你想要

When you hit a url it will take you to this function shouldOverrideUrlLoading where you can call an intent or do anything you want

这篇关于的WebView URL过滤的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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