Android 常见的工具类
/**
* 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 常见的工具类的更多相关文章
- Android 软件管理工具类Utils
Android 软件管理工具类Utils /** * Created by uilubo on 2015/9/30. * 工具类 */ public class Utils { public stat ...
- (转载)实例详解Android快速开发工具类总结
实例详解Android快速开发工具类总结 作者:LiJinlun 字体:[增加 减小] 类型:转载 时间:2016-01-24我要评论 这篇文章主要介绍了实例详解Android快速开发工具类总结的相关 ...
- 一个使用命令行编译Android项目的工具类
一个使用命令行编译Android项目的工具类 简单介绍 编译apk项目须要使用的几个工具,基本都在sdk中,它们各自是(Windows系统): 1.aapt.exe 资源打包工具 2.android. ...
- Android开发常用工具类
来源于http://www.open-open.com/lib/view/open1416535785398.html 主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前 ...
- Android常用的工具类
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Prefe ...
- Android常用的工具类(转)
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils.Prefer ...
- 2013最新Android常用的工具类整理
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Pref ...
- 最全Android开发常用工具类
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括 HttpUtils.DownloadManagerPro.Safe.ijiami.ShellUtils.Pack ...
- android下载简单工具类
功能是实现下载文件,图片或MP3等,为了简单起见使用单线程,此代码为MarsAndroid教程的复制品,放在此处,留着参考. 首先是一个得到字节流随后保存到内存卡上的工具类: package com. ...
随机推荐
- HDU4763 Theme Section —— KMP next数组
题目链接:https://vjudge.net/problem/HDU-4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) Mem ...
- android TextView 设置部分文字背景色 和 文字颜色
通过SpannableStringBuilder来实现,它就像html里边的元素改变指定文字的文字颜色或背景色 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- linux防火墙过滤规则
一.linux防火墙基础 防火墙分为硬件防火墙和软件防火墙. 1.概述 linux 防火墙体系主要工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙. 包过滤机制:netfil ...
- 关于python代码的性能
在python中性能测试是一个很难应付的任务,因为它在反复地优化,也许版本和版本之间差别很大.python中的一个主要的原则是,首先为了简单和可读性去编写代码,在程序运行后,并证明了确实有必要考虑性能 ...
- 【CQ18阶梯赛第一场】题解
[A-风格不统一如何写程序] 输入字符串,得到长度,对于每个字符:如果是大写,则改为:‘_’+小写:如果是‘_’则忽略‘_’,并且把后面的小写改为大写. #include<cstdio> ...
- CodeForces-607B:Zuma (基础区间DP)
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the ...
- CodeForces-816B:Karen and Coffee (简单线段树)
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- macbook pro 下eclipse配置svn插件
eclipse中最常使用的SVN插件是subclipse,先到subclipse官网:http://subclipse.tigris.org下载该插件. 如上图,点击“Download and I ...
- Android应用开发完全退出程序的通用方法
在开发一个android应用时,有可能有N个Activity,而在每个Activity里的菜单里有个"退出程序"菜单,这里就要完全退出程序了,所以今天给大家分享的是Android应 ...
- 启动和测试oracle是否安装成功
转自:https://www.cnblogs.com/justdo-it/articles/5112576.html 测试步骤1:请执行操作系统级的命令:tnsping orcl 测试步骤 2:请执行 ...