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. ...
随机推荐
- bzoj3137: [Baltic2013]tracks
炸一看好像很神仙的样子,其实就是个sb题 万年不见的1A 但是我们可以反过来想,先选一个起点到终点的联通块,然后这联通块后面相当于就能够走了,继续找联通块 然后就能发现直接相邻的脚步相同的边权为0,否 ...
- 各种DP总结
一.数位DP 1.含有或不含某个数“xx”: HDU3555 Bomb HDU2089 不要62 2.满足某些条件,如能整除某个数,或者数位上保持某种特性: HDU3652 B-number Code ...
- LightOJ - 1422 Halloween Costumes —— 区间DP
题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes PDF (English) Statistics F ...
- 多态、抽象类、接口、区别(java基础知识九)
1.多态的概述以及代码体现 * A:多态概述 * 事物存在的多种形态 * B:多态前提 * a:要有继承关系. * 一个类是父类,一个类是子类 * b:要有方法重写. * c:要有父类引用指向子类对象 ...
- LA-3716(sort的神用)
题意: 给出两条长度均为n的NDA链A和B,找出一段最长的字串[l,r]使得该区域的突变位置不超过p%; 思路: sum[i]表示[1,i]中不相同的个数,可得表达式(sum[i]-sum[j])/( ...
- 搜索好题UVA1601
题目 分析:如果以当前3个小写字母的位置为状态,则问题转化为图上的最短路问题.但是如果每次都判断小写字母的下一步是否合法,那就是说每次移动都需要判断5^3,肯定会超时.可以把所有可以移动的格子找出来建 ...
- 怎么解决Failed to load the JNI shared library
怎么解决Failed to load the JNIshared library 解决Failed to load the JNIshared library唯一的方法就是重新安装eclipse, ...
- jQuery中排除指定元素,同时选择剩下的所有元素
场景:某页面用了js延时加载技术处理所有图片,以改善用户体验,但是有几个图片不想延时加载,要求把它们单独挑出来. 研究了一下jQuery的API文档,搞掂了,jQuery真的很方便,贴在这里备份: 1 ...
- bzoj 4260 REBXOR —— Trie树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 用 Trie 树可以找出前缀异或的最大值和后缀异或的最大值,拼起来即可: 注意要先加入 ...
- 关于cout输出精度问题
#include <iostream.h> #include <iomanip.h> void main(void) { cout.setf(ios::fixed); cout ...