问题描述
我用 webview 创建了应用程序,我想在 webview 中加载所有内部链接并在 android 浏览器中加载外部链接.现在的问题是我正在使用 html 广告,当我点击广告时,我想打开外部浏览器,但它在 webview 中打开.唯一的问题是广告,否则一切正常.那么我该怎么做呢?
I created app with webview, and i want load all internal links in webview and load external links in android browser. Now problem is I am using html ads and when i click on ads i want open external browser, but its opening in webview. only problem with ads otherwise everything is works fine. So how can i do this?
我的代码如下:
`class MyWebViewClient 扩展了 WebViewClient {
`class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().equals("www.mysite.com")) {
view.loadUrl(url);
return true;
}else{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;}}`
推荐答案
我做了一些修改,它非常适合横幅广告.我进行了以下更改:
I did the some modifications and it is working perfectly for banner ads.I have made following changes:
- 如果条件发生变化.
- 我为if"块返回 false,如文档所述:
如果提供了 WebViewClient,则返回 true 表示宿主应用程序处理 url,而 return false 表示当前的 WebView 处理网址
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contains("www.mysite.com"))
{
view.loadUrl(url);
return false;
}else
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
这篇关于在webview android中在外部浏览器中打开广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!