android - android中的webview主机应用程序
问题描述
我是初学者。当我开始使用 webview 制作应用程序时。
当即将在当前 WebView 中加载 URL 时,让宿主应用程序有机会进行控制。
我英语很弱,但我知道什么是托管。但我不明白什么是主机应用程序,为什么它会这样调用?
1)主机应用程序是指我的应用程序中的网络浏览器或网络视图吗?
2) shouldoverrideurlloading 如何与 webview 和浏览器一起使用应该会有所帮助。
3) return true 会打开一个网络浏览器??
解决方案
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
final Uri uri = Uri.parse(url);
return handleUri(view, uri);
}
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
final Uri uri = request.getUrl();
return handleUri(view, uri);
}
和 handleUri 方法
private boolean handleUri(WebView view, Uri uri) {
final String scheme = uri.getScheme();
final String host = uri.getHost();
// Based on some condition you need to determine if you are going to load the url
// in your web view itself or in a browser.
// You can use `host` or `scheme` or any part of the `uri` to decide.
if (scheme.startsWith("http:") || scheme.startsWith("https:")) {
view.loadUrl(uri.getPath());
return true;
} else {
return false;
}
}
推荐阅读
- sql - 根据sql中的行条件从行中获取数据
- javascript - Is it possible to read from the terminal using Cypress?
- python - 使用特定的旧 setuptools 版本创建 virtualenv
- php - Woocommerce 计算后获取价格
- linux - 无法打开以前登录的亚马逊网站,无法向 gitlab 上传新密钥,无法加入 slack 通话或上传文件
- octave - 有没有办法以八度音阶将多个矩阵存储在向量中?
- android - Android:透明活动的问题
- c++ - 在数独上并行回溯不增加使用的 %cpu
- r - 嵌套模块中输入的反应性
- docker-compose - ksql 在 Fargate 上部署 ksqldb-server docker-compose 映像时缺少所需的配置“bootstrap.servers”,该配置没有默认值