zoukankan      html  css  js  c++  java
  • android 中wifi的应用

    加入权限

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

    主要代码 

    //打开状态
       wifiManager=(WifiManager)ActivityMain.this.getSystemService(Context.WIFI_SERVICE);
       wifiManager.setWifiEnabled(true);
       System.out.println("wifi state-->"+wifiManager.getWifiState());
       Toast.makeText(ActivityMain.this, "当前wifi网卡状态为"+wifiManager.getWifiState(), Toast.LENGTH_SHORT).show();
      }
        
        }
    //关闭状态    
       wifiManager=(WifiManager)ActivityMain.this.getSystemService(Context.WIFI_SERVICE);
       wifiManager.setWifiEnabled(false);
       System.out.println("wifi state-->"+wifiManager.getWifiState());
       Toast.makeText(ActivityMain.this, "当前wifi网卡状态为"+wifiManager.getWifiState(), Toast.LENGTH_SHORT).show();
      }
         //检查状态
         wifiManager=(WifiManager)ActivityMain.this.getSystemService(Context.WIFI_SERVICE);
       //wifiManager.setWifiEnabled(false);
       System.out.println("wifi state-->"+wifiManager.getWifiState());
       Toast.makeText(ActivityMain.this, "当前wifi网卡状态为"+wifiManager.getWifiState(), Toast.LENGTH_SHORT).show();
      }
        
        }
    }

    相关连接http://lpqsun-126-com.iteye.com/blog/1087847

    http://zkl-1987.iteye.com/blog/1054913

  • 相关阅读:
    Business talking in English
    My strength (C-A-R)
    牛排有几分熟怎么说
    深入理解 Java try-with-resource 语法糖
    什么时候用异常,什么时候用断言?
    Java陷阱之assert关键字
    Java断言绝对不是鸡肋
    Java 条件编译
    Java 语法糖详解
    Java中有哪些语法糖?
  • 原文地址:https://www.cnblogs.com/baiting/p/5346401.html
Copyright © 2011-2022 走看看