gpt4 book ai didi

webview - 在 webview android 的外部浏览器中打开广告

转载 作者:行者123 更新时间:2023-12-05 05:27:56 27 4
gpt4 key购买 nike

我用 webview 创建了应用程序,我想在 webview 中加载所有内部链接并在 android 浏览器中加载外部链接。现在的问题是我正在使用 html 广告,当我点击广告时我想打开外部浏览器,但它在 webview 中打开。唯一的问题是广告,否则一切正常。那我该怎么做呢?

我的代码如下:

`类 MyWebViewClient 扩展 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;}}`

最佳答案

你的代码应该是:

@Override   
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.mysite.com")) {
return true;
}else{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return false;
}
}

所有我改变的是:

1.) 返回 true 加载 webview 中的 URL,不需要 view.loadUrl()

2.) 广播 ACTION_VIEW 意图时返回 false

关于webview - 在 webview android 的外部浏览器中打开广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15332421/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com