<tfoot id='qARes'></tfoot>
    <bdo id='qARes'></bdo><ul id='qARes'></ul>

<legend id='qARes'><style id='qARes'><dir id='qARes'><q id='qARes'></q></dir></style></legend>
      <i id='qARes'><tr id='qARes'><dt id='qARes'><q id='qARes'><span id='qARes'><b id='qARes'><form id='qARes'><ins id='qARes'></ins><ul id='qARes'></ul><sub id='qARes'></sub></form><legend id='qARes'></legend><bdo id='qARes'><pre id='qARes'><center id='qARes'></center></pre></bdo></b><th id='qARes'></th></span></q></dt></tr></i><div id='qARes'><tfoot id='qARes'></tfoot><dl id='qARes'><fieldset id='qARes'></fieldset></dl></div>

      1. <small id='qARes'></small><noframes id='qARes'>

        如何以编程方式检查 Android 中互联网连接的可用性?

        时间:2023-06-26

        <i id='i5577'><tr id='i5577'><dt id='i5577'><q id='i5577'><span id='i5577'><b id='i5577'><form id='i5577'><ins id='i5577'></ins><ul id='i5577'></ul><sub id='i5577'></sub></form><legend id='i5577'></legend><bdo id='i5577'><pre id='i5577'><center id='i5577'></center></pre></bdo></b><th id='i5577'></th></span></q></dt></tr></i><div id='i5577'><tfoot id='i5577'></tfoot><dl id='i5577'><fieldset id='i5577'></fieldset></dl></div>
      2. <small id='i5577'></small><noframes id='i5577'>

                <bdo id='i5577'></bdo><ul id='i5577'></ul>
                  <tbody id='i5577'></tbody>

              • <legend id='i5577'><style id='i5577'><dir id='i5577'><q id='i5577'></q></dir></style></legend>

                  <tfoot id='i5577'></tfoot>
                  本文介绍了如何以编程方式检查 Android 中互联网连接的可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想以编程方式检查 Android 手机/模拟器中是否有互联网连接.因此,一旦我确定存在互联网连接,我就会拨打互联网电话.

                  I want to check programmatically whether there is an internet connection in Android phone/emulator. So that once I am sure that an internet connection is present then I'll make a call to the internet.

                  所以它就像嘿模拟器!如果你有互联网连接,那么请打开这个页面,否则 doSomeThingElse();"

                  So its like "Hey emulator! If you have an internet connection, then please open this page, else doSomeThingElse();"

                  推荐答案

                  我自己实现的方法:

                  /*
                   * isOnline - Check if there is a NetworkConnection
                   * @return boolean
                   */
                  protected boolean isOnline() {
                      ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                      NetworkInfo netInfo = cm.getActiveNetworkInfo();
                      if (netInfo != null && netInfo.isConnected()) {
                          return true;
                      } else {
                          return false;
                      }
                  }
                  

                  请注意,这是一个 NetworkConnection-Check.如果有 NetworkConnection,它不一定是 InternetConnection.

                  Be aware of that this is a NetworkConnection-Check. If there is a NetworkConnection it doesn't have to be a InternetConnection.

                  这篇关于如何以编程方式检查 Android 中互联网连接的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android 模拟器错误:“系统 UI 已停止" 下一篇:如何在运行时获取设备高度和宽度?

                  相关文章

                  1. <tfoot id='e9DJB'></tfoot>
                    <i id='e9DJB'><tr id='e9DJB'><dt id='e9DJB'><q id='e9DJB'><span id='e9DJB'><b id='e9DJB'><form id='e9DJB'><ins id='e9DJB'></ins><ul id='e9DJB'></ul><sub id='e9DJB'></sub></form><legend id='e9DJB'></legend><bdo id='e9DJB'><pre id='e9DJB'><center id='e9DJB'></center></pre></bdo></b><th id='e9DJB'></th></span></q></dt></tr></i><div id='e9DJB'><tfoot id='e9DJB'></tfoot><dl id='e9DJB'><fieldset id='e9DJB'></fieldset></dl></div>
                    <legend id='e9DJB'><style id='e9DJB'><dir id='e9DJB'><q id='e9DJB'></q></dir></style></legend>
                        <bdo id='e9DJB'></bdo><ul id='e9DJB'></ul>

                      <small id='e9DJB'></small><noframes id='e9DJB'>