我正在尝试从android连接Node服务器插座用于Live Order track目的,我无法在版本9的Android设备中连接到服务器,但在较低版本中工作良好。我没有从服务器获取LatLog,但它正在从较低的设备中获取。我也在使用FCM作为通知用途。
android:usesCleartextTraffic="true" 上面的Manifest行在我的例子中不起作用
请在下面找到我的代码
private void ConnectSocket() {
try {
final JSONObject objInit = new JSONObject();
// objInit.put ("user_joined", bookingKey);
objInit.put("user_joined", bookingKey);
if (socket == null) {
socket = IO.socket(Urls.socketUrl);
} else {
System.out.println("Socket is already connected");
}
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
socket.emit("user_joined", bookingKey);
locationList.clear();
}
}).on("authenticated", new Emitter.Listener() {
@Override
public void call(Object... args) {
}
}).on("event", new Emitter.Listener() {
@Override
public void call(Object... args) {
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
}
}).on("newlocation", new Emitter.Listener() {
@Override
public void call(Object... args) {
}
})
.on(bookingKey, new Emitter.Listener() {
@Override
public void call(Object... args) {
final String taxiDetails = args[0].toString();
System.out.println("Received from Socket :" + args[0].toString());
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject Job_CarDetails = new JSONObject(taxiDetails);
String latitude = Job_CarDetails.getString("latitude");
String longitude = Job_CarDetails.getString("longitude");
if (locationList.size() == 0) {
MarkerOptions mMarkerOptions = new MarkerOptions().position(new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude)))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_van));
Marker mMarker = googleMap.addMarker(mMarkerOptions);
MarkerList markerList = new MarkerList();
markerList.setLatitude(latitude);
markerList.setLongitude(longitude);
markerList.setMarker(mMarker);
locationList.add(markerList);
} else {
LatLng mToPosition = new LatLng(Double.parseDouble(latitude), Double.parseDouble(longitude));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (!socket.connected()) {
try {
socket.connect();
socket.emit("user_joined", bookingKey);
locationList.clear();
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
}
}如何修改代码以将版本9的设备连接到服务器??任何帮助都将不胜感激。
发布于 2020-03-11 13:18:12
这个问题不是来自Android端,而是在服务器端。当服务器移动到活动服务器时,由于本地服务器指向,套接字连接正常工作而引发此情况。谢谢。
https://stackoverflow.com/questions/60387753
复制相似问题