/**
* Wifi 管理类
*
* @author Administrator
* 使用方法
* WifiManagerUtils wifiManager = new WifiManagerUtils(context);
if (wifiManager.isConnection())
{
Intent intent = new Intent(context, AseoZdpUpdateService.class);
context.startService(intent);
}
*
*/
public class WifiManagerUtils {
private WifiManager mWifiManager;
private WifiInfo mWifiInfo;
private List<ScanResult> mWifiList;
private List<WifiConfiguration> mWifiConfiguration; public WifiManagerUtils(Context context) {
this.mWifiManager = ((WifiManager) context.getSystemService("wifi")); this.mWifiInfo = this.mWifiManager.getConnectionInfo();
} public boolean isConnection() {
this.mWifiInfo = this.mWifiManager.getConnectionInfo(); return (this.mWifiManager.isWifiEnabled()) && (this.mWifiInfo != null)
&& (this.mWifiInfo.getBSSID() != null)
&& (this.mWifiInfo.getIpAddress() != );
} public boolean isConnection(String ssid) {
this.mWifiInfo = this.mWifiManager.getConnectionInfo();
if ((!this.mWifiManager.isWifiEnabled()) || (this.mWifiInfo == null))
return false;
String string = this.mWifiInfo.getSSID(); return string.contains(ssid);
} public int checkState() {
return this.mWifiManager.getWifiState();
} public List<WifiConfiguration> getConfiguration() {
return this.mWifiConfiguration;
} public void connectConfiguration(int index) {
if (index > this.mWifiConfiguration.size()) {
return;
} this.mWifiManager
.enableNetwork(
((WifiConfiguration) this.mWifiConfiguration.get(index)).networkId,
true);
} public void startScan() {
this.mWifiManager.startScan(); this.mWifiConfiguration = this.mWifiManager.getConfiguredNetworks();
} public List<ScanResult> getWifiList() {
this.mWifiList = this.mWifiManager.getScanResults();
return this.mWifiList;
} public StringBuilder lookUpScan() {
StringBuilder stringBuilder = new StringBuilder();
for (int i = ; i < this.mWifiList.size(); i++) {
stringBuilder
.append("Index_" + new Integer(i + ).toString() + ":"); stringBuilder.append(((ScanResult) this.mWifiList.get(i))
.toString());
stringBuilder.append("/n");
}
return stringBuilder;
} public String getMacAddress() {
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.getMacAddress();
} public String getBSSID() {
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.getBSSID();
} public String getSSID() {
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.getSSID();
} public int getIPAddress() {
return this.mWifiInfo == null ? : this.mWifiInfo.getIpAddress();
} public int getNetworkId() {
return this.mWifiInfo == null ? : this.mWifiInfo.getNetworkId();
} public String getWifiInfo() {
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.toString();
} public void disconnectWifi(int netId) {
this.mWifiManager.disableNetwork(netId);
this.mWifiManager.disconnect();
} public String Connect(String SSID, String Password, WifiCipherType type) {
if (!this.mWifiManager.isWifiEnabled()) {
return null;
} this.mWifiInfo = this.mWifiManager.getConnectionInfo();
String ssidString = getSSID();
if ((ssidString != null) && (ssidString.contains("\""))) {
ssidString = ssidString.split("\"")[];
} WifiConfiguration oldConfig = IsExsits(ssidString);
if (oldConfig != null) {
disconnectWifi(oldConfig.networkId);
} WifiConfiguration tempConfig = CreateWifiInfo(SSID, Password, type);
int tempID = this.mWifiManager.addNetwork(tempConfig);
boolean ret = this.mWifiManager.enableNetwork(tempID, true);
this.mWifiManager.reconnect(); return ssidString;
} public boolean RemoveWifiConfig(String ssid) {
WifiConfiguration Config = IsExsits(ssid);
if (Config == null) {
return false;
}
this.mWifiManager.disableNetwork(Config.networkId);
this.mWifiManager.removeNetwork(Config.networkId);
return true;
} public boolean Connect(String ssid) {
if ((ssid != null) && (ssid.contains("\""))) {
ssid = ssid.split("\"")[];
}
WifiConfiguration tempConfig = IsExsits(ssid);
if (tempConfig != null) {
boolean bRet = this.mWifiManager.enableNetwork(
tempConfig.networkId, true);
this.mWifiManager.reconnect();
}
return true;
} public WifiConfiguration IsExsits(String SSID) {
List existingConfigs = this.mWifiManager.getConfiguredNetworks();
for (WifiConfiguration existingConfig : existingConfigs) {
if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
return existingConfig;
}
}
return null;
} private WifiConfiguration CreateWifiInfo(String SSID, String Password,
WifiCipherType type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = ("\"" + SSID + "\""); if (type == WifiCipherType.WIFICIPHER_NOPASS) {
config.hiddenSSID = true;
config.allowedKeyManagement.set();
} else if (type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = ("\"" + Password + "\"");
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set();
config.allowedGroupCiphers.set();
config.allowedKeyManagement.set();
config.allowedPairwiseCiphers.set(); config.allowedGroupCiphers.set();
config.allowedPairwiseCiphers.set();
config.status = ;
} else if (type == WifiCipherType.WIFICIPHER_WEP) {
config.hiddenSSID = true;
config.wepKeys[] = ("\"" + Password + "\"");
config.allowedAuthAlgorithms.set();
config.allowedGroupCiphers.set();
config.allowedGroupCiphers.set();
config.allowedGroupCiphers.set();
config.allowedGroupCiphers.set();
config.allowedKeyManagement.set();
config.wepTxKeyIndex = ;
}
return config;
} public static enum WifiCipherType {
WIFICIPHER_WEP, WIFICIPHER_WPA, WIFICIPHER_NOPASS, WIFICIPHER_INVALID;
}
}

Android 常见的工具类的更多相关文章

  1. Android 软件管理工具类Utils

    Android 软件管理工具类Utils /** * Created by uilubo on 2015/9/30. * 工具类 */ public class Utils { public stat ...

  2. (转载)实例详解Android快速开发工具类总结

    实例详解Android快速开发工具类总结 作者:LiJinlun 字体:[增加 减小] 类型:转载 时间:2016-01-24我要评论 这篇文章主要介绍了实例详解Android快速开发工具类总结的相关 ...

  3. 一个使用命令行编译Android项目的工具类

    一个使用命令行编译Android项目的工具类 简单介绍 编译apk项目须要使用的几个工具,基本都在sdk中,它们各自是(Windows系统): 1.aapt.exe 资源打包工具 2.android. ...

  4. Android开发常用工具类

    来源于http://www.open-open.com/lib/view/open1416535785398.html 主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前 ...

  5. Android常用的工具类

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Prefe ...

  6. Android常用的工具类(转)

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils.Prefer ...

  7. 2013最新Android常用的工具类整理

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Pref ...

  8. 最全Android开发常用工具类

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括  HttpUtils.DownloadManagerPro.Safe.ijiami.ShellUtils.Pack ...

  9. android下载简单工具类

    功能是实现下载文件,图片或MP3等,为了简单起见使用单线程,此代码为MarsAndroid教程的复制品,放在此处,留着参考. 首先是一个得到字节流随后保存到内存卡上的工具类: package com. ...

随机推荐

  1. WinDbg设置托管进程断点

    WinDbg的Live模式调试..Net 托管代码 ,使用bp,bu,bm无法设置断点,也许是我不会.研究了下,托管代码有自己的命令,!BPMD 模块名 完全限定的方法名 步骤: 1.查找进程PID, ...

  2. 阿里云短信服务发送短信验证码(JAVA开发此功能)

    开发此功能需注册阿里云账号,并开通短信服务(免费开通) 充值后,不会影响业务的正常使用!(因为发送验证类短信:1-10万范围的短信是0.045元/条).开发测试使用,充2块钱测试足够了 可参考阿里云官 ...

  3. iOS多线程全套:线程生命周期,多线程的四种解决方案,线程安全问题,GCD的使用,NSOperation的使用

    目的 本文主要是分享iOS多线程的相关内容,为了更系统的讲解,将分为以下7个方面来展开描述. 多线程的基本概念 线程的状态与生命周期 多线程的四种解决方案:pthread,NSThread,GCD,N ...

  4. cassandra解析-log写

    db/Keyspace.java 中的 apply 函数 中的 commitLogPosition = CommitLog.instance.add(mutation); 这一句确认是写log的代码. ...

  5. oracle实例的内存(SGA和PGA)调整,优化数据库性能

    一.名词解释 (1)SGA:SystemGlobal Area是OracleInstance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池.数据缓冲区.日志缓冲区. (2) ...

  6. BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS

    BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS Description Farmer John has taken the cows to a va ...

  7. 【转】Chrome headless 模式

    原文地址: http://www.cnblogs.com/fnng/p/7797839.html 我们在通过Selenium运行自动化测试时,必须要启动浏览器,浏览器的启动与关闭必然会影响执行效率,而 ...

  8. codeforces 724D

    注意到要字典序最小,从而变为水题. 从a选到z,每次必然是先看选部分当前字符x是否能满足覆盖,若不能则选上所有的字母x,不然break,输出答案. 进行26次dp即可. #include <cs ...

  9. BZOJ1787 meet

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1787 水题,但是结论很有趣. 题目求的是距离三个点之和最小的点. 这个很显然是在三个LCA上, ...

  10. 模板 - 字符串 - Manacher

    求最长回文子串. #include<bits/stdc++.h> using namespace std; #define ll long long ; ]; ]; int Manache ...