zoukankan      html  css  js  c++  java
  • 判断网络状态

    <uses-permission
    android:name="android.permission.ACCESS_NETWORK_STATE" />

    private boolean getNetWorkStatus() {

    boolean netSataus = false;
    ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    cwjManager.getActiveNetworkInfo();

    if (cwjManager.getActiveNetworkInfo() != null) {
      netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
    }

    if (!netSataus) {
      Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")
                          .setMessage("是否对网络进行设置?");
                          b.setPositiveButton("是", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {

                                  Intent mIntent = new Intent("/");
                                  ComponentName comp = new ComponentName( "com.android.settings", "com.android.settings.WirelessSettings");
                                  mIntent.setComponent(comp);
                                  mIntent.setAction("android.intent.action.VIEW");
                                  startActivityForResult(mIntent,0);
                              }
                              }).setNeutralButton("否", new DialogInterface.OnClickListener() {
                                  public void onClick(DialogInterface dialog, int whichButton) {
                                      dialog.cancel();
                                  }
                           }).show();
      }

                  return netSataus;
    }

  • 相关阅读:
    java一个简单的线程池小例子
    java通过反射复制实体类
    java通过反射获取Object的属性
    java时间对比
    软件工程基础最后第一次作业 总结
    C++语言程序化设计——第五次作业
    软件工程基础——第四次作业
    C++语言程序化设计——第四次作业
    软件工程基础第三次作业——原型设计
    C++语言程序化设计——第三次作业
  • 原文地址:https://www.cnblogs.com/bravolove/p/5029330.html
Copyright © 2011-2022 走看看