HarmonyOS 鸿蒙Next 使用webview加载离线腾讯地图闪退

HarmonyOS 鸿蒙Next 使用webview加载离线腾讯地图闪退

api是7 语言是Java

本地html文件部分代码:

```php
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>画折线</title>
</head>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
<style>
    /* html,
    body {
        height: 100%;
        margin: 0px;
        padding: 0px;
    }

    #container {
        width: 100%;
        height: 100%;
    } */

    html,body{
    width:100%;
    height:100%;
}
#container{
    width:100%;
    height:100%;
}
*{
    margin:0px;
    padding:0px;
}
body, button, input, select, textarea {
    font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
p{
    width:603px;
    padding-top:3px;
    overflow:hidden;
}
</style>

<body onload="initMap()">
<div id="container"></div>
<script>
        var markerLayer;
        function initMap() {
            //初始化地图
            var map = new TMap.Map('container', {
                center: new TMap.LatLng(37.794162,112.590773),//地图显示中心点
                zoom:16    //缩放级别
            });
            //创建 MultiPolyline
      polylineLayer = new TMap.MultiPolyline({
         id: 'polyline-layer', //图层唯一标识
         map:map,//绘制到目标地图
         //折线样式定义
         styles: {
            'style_blue': new TMap.PolylineStyle({
               'color':'#3777FF', //线填充色
               'width':6, //折线宽度
               'borderWidth':5, //边线宽度
               'borderColor':'#FFF', //边线颜色
               'lineCap':'butt' //线端头方式
            }),
            'style_red': new TMap.PolylineStyle({
               'color':'#CC0000', //线填充色
               'width':6, //折线宽度
               'borderWidth':5, //边线宽度
               'borderColor':'#CCC', //边线颜色
               'lineCap':'round' //线端头方式
            })
         },
    //折线数据定义
         geometries: [
            //{第1条线}
               'id':'pl_1',//折线唯一标识,删除时使用
               'styleId':'style_blue',//绑定样式名
               'paths': [new TMap.LatLng(40.038540, 116.272389), new TMap.LatLng(40.038844, 116.275210), new TMap.LatLng(40.041407, 116.274738)]
            },
            //{第2条线}
               'id':'pl_2',
               'styleId':'style_red',
               'paths': [new TMap.LatLng(37.794162,112.590773), new TMap.LatLng(37.7945,112.590773), new TMap.LatLng(37.794162,112.591)]
            }
         ]
      });
        }
</script>
</body>

估计是webGL的原因,不太确定,不知道怎么解决

java部分代码:

private void initView() {
    webview = findComponentById(ResourceTable.Id_webview);
    webview.getWebConfig().setDataAbilityPermit(true);  //这个要加上,设置 webview 支持打开本地文件
    initCallJsButton();
    configWebView();
    webview.load(URL_LOCAL);
}
private void configWebView() {
    WebConfig webConfig = webview.getWebConfig();
    // 是否支持Javascript,默认值false
    webConfig.setJavaScriptPermit(true);
    webview.setWebAgent(new WebAgent() {
        @Override
        public boolean isNeedLoadUrl(WebView webView, ResourceRequest request) {
            if (request == null || request.getRequestUrl() == null) {
                return false;
            }
            String url = request.getRequestUrl().toString();
            if (url.startsWith("http:") || url.startsWith("https:")) {
                webView.load(url);
                return false;
            } else {
                return super.isNeedLoadUrl(webView, request);
            }
        }
    });

    webview.setBrowserAgent(new BrowserAgent(this) {
        @Override
        public boolean onJsMessageShow(WebView webView, String url, String message, boolean isAlert, JsMessageResult result) {
            if (isAlert) {
                new ToastDialog(getApplicationContext()).setText(message).setAlignment(LayoutAlignment.CENTER).show();
                result.confirm();
                return true;
            } else {
                return super.onJsMessageShow(webView, url, message, isAlert, result);
            }
        }
    });

    // 配置JS发来的消息处理
    webview.addJsCallback(JS_NAME, str -> {
        // 处理接收到的Js发送来的消息
        new ToastDialog(this).setText(str).setAlignment(LayoutAlignment.CENTER).show();
        // 返回给Js
        return "Js Call Java Success";
    });
}

以下是报错:

E/hwschromium-4397: [ERROR:render_process_host_impl.cc(5271)] Terminating render process for bad Mojo message: Received bad user message: URL with invalid origin passed to BlobURLStore::Register

[ERROR:bad_message.cc(29)] Terminating renderer for bad IPC message, reason 123

I/AwareBitmapCacher: init lrucache size: 2097152 pid=31849

I/hwschromium-4397: [INFO:network_service_network_delegate.cc(246)] final url https//*** error_code -3 ip address: ignored

E/hwschromium-4397: [ERROR:aw_contents.cc(2215)] HWBFCACHE: RenderFrameDeleted had cached this RFH 0

E/hwschromium-4397: [ERROR:aw_browser_terminator.cc(123)] Renderer process (32742) crash detected (code -1).

E/hwschromium-4397: [ERROR:aw_browser_terminator.cc(89)] Render process (32742) kill (OOM or update) wasn’t handed by all associated webviews, killing application。


更多关于HarmonyOS 鸿蒙Next 使用webview加载离线腾讯地图闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

您好,请您通过在线提单进一步解决: https://developer.huawei.com/consumer/cn/support/feedback/#/, 感谢您的反馈和支持。

更多关于HarmonyOS 鸿蒙Next 使用webview加载离线腾讯地图闪退的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


遇到相同的问题,在Webview中加载高德地图,也报上面的问题,小米手机正常,mate40闪退,楼主解决了吗?

同样的问题,可有解决呢?

遇到相同的问题,楼主解决了吗?

遇到相同的问题,楼主解决了吗?

针对HarmonyOS鸿蒙Next使用webview加载离线腾讯地图闪退的问题,可能的原因及解决方案如下:

  1. 离线地图资源问题

    • 确认离线地图资源是否完整且适用于鸿蒙系统。不同平台(如Android、iOS)的离线地图资源可能不兼容,需确保使用的是鸿蒙系统专用的离线地图包。
  2. webview配置问题

    • 检查webview的配置,确保已正确设置加载本地资源的权限和路径。鸿蒙系统的webview配置可能与Android有所不同,需参考鸿蒙官方文档进行调整。
  3. 系统兼容性问题

    • 鸿蒙系统可能尚未完全兼容所有Android应用,特别是涉及到底层系统调用和资源管理的应用。尝试更新鸿蒙系统至最新版本,或查看腾讯地图是否有针对鸿蒙系统的适配版本。
  4. 内存和资源管理

    • 离线地图数据较大,加载时可能占用大量内存。检查应用是否有内存泄漏或资源管理不当的问题,优化代码以提高资源利用效率。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部