我正在使用signalr进行聊天api,信号器服务正在启动并获取聊天消息一段时间,但是,在一段时间后,信号器集线器连接没有响应,我无法联系signalR服务器。如何在android中检查signalr hubconnection是否在线。
答案 0 :(得分:0)
尝试这种方法
public static boolean isInternetOn(Context context) {
ConnectivityManager connec = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED
|| mWifi.isConnectedOrConnecting()) {
return true;
} else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED ||
connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED ||
mWifi.getState() == NetworkInfo.State.DISCONNECTED) {
return false;
}
return false;
}
答案 1 :(得分:0)
当您调用此方法而不是此实例时,您可以获得当前的hubconnection状态。
List<JButton> items = Arrays.asList(new JButton(), new JButton(), new JButton());
System.out.println(items);
Collections.shuffle(items);
items.get(0).setEnabled(true);