Java me 如何检查j2me(LUIT)中的互连是否可用

Java me 如何检查j2me(LUIT)中的互连是否可用,java-me,Java Me,在我的应用程序中,我想使用j2me中的对话框(LWIIT)检查gprsconnection,有人知道吗?只需打开一个地址即可 private boolean isNetworkAvailable() { boolean result = false; HttpConnection httpConnection = null; try { httpConnection = (HttpConnection) Connector.open("http://www.google.co

在我的应用程序中,我想使用j2me中的对话框(LWIIT)检查gprsconnection,有人知道吗?

只需打开一个地址即可

private boolean isNetworkAvailable() {
  boolean result = false;
  HttpConnection httpConnection = null;
  try {
    httpConnection = (HttpConnection) Connector.open("http://www.google.com");
    result = true;
  } catch (Exception e) {
  }
  return result;
}

在打开“尝试获取响应代码”的输入流之前,上述代码不会执行任何http调用。您不需要执行任何http调用来检查Internet连接是否可用。您只需要看看是否可以创建HttpConnection。如果没有Internet配置文件,或者配置文件无效,那么它将无法创建HttpConnection。