我有一个html文件,我在android studio中的webview中运行它,但它不与www.example.com连接socket.io,html文件没有问题,因为相同的文件在计算机上连接。
这是我的HTML文件:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Popup Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./leaflet/leaflet.css"/>
<script src="./leaflet/leaflet.js"></script>
<script src="./socket_io.js"></script>
</head>
<body>
<div id="mapid" style="height: 100vh;"></div>
<script>
var socket = io("http://xxxxx:3000");
var mymap = L.map('mapid').setView([39.9042, 32.6227], 5);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(mymap);
var placedMarkers = [];
socket.on("clientLocations", (data) => {
placedMarkers.forEach(function(placedMarkers) {
mymap.removeLayer(placedMarkers);
});
placedMarkers = [];
markers = data;
var bounds = [];
for (var i = 0; i < markers.length; i++) {
var marker = L.marker(markers[i].location).addTo(mymap);
placedMarkers.push(marker);
var popup = L.popup({
autoClose: false,
closeOnClick: false,
closeButton: false,
}).setContent(markers[i].name);
marker.bindPopup(popup).openPopup();
bounds.push(markers[i].location);
}
mymap.fitBounds(bounds, { padding: [100, 100], maxZoom: 100 });
});
</script>
</body>
</html>
这是我的Kotlin代码:
val webView: WebView = findViewById(R.id.web_view);
webView.settings.javaScriptEnabled = true;
webView.loadUrl("file:///android_asset/html/index.html")
我有这些权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1条答案
按热度按时间mrfwxfqh1#
我补充道
到**
AndroidManifest.xml
**文件中的应用程序标记,问题解决。感谢Blackapps的评论和给我的解决方案。