Wifi涉及到的API
来源:互联网 发布:node培训 编辑:程序博客网 时间:2024/05/17 22:08
下边是封装好的一个wifi操作类package jia.wifitest1;import android.content.Context;import android.net.wifi.ScanResult;import android.net.wifi.WifiConfiguration;import android.net.wifi.WifiInfo;import android.net.wifi.WifiManager;import java.util.List;/** * Created by jiawenchao on 2015/12/7. */public class WifiTools { private String TAG="WifiTools"; private WifiManager wifiManager; private WifiInfo wifiInfo; private List<ScanResult> wifiList=null; public WifiTools(Context context){ this.wifiManager= (WifiManager) context.getSystemService(Context.WIFI_SERVICE); } public boolean isWifiOpen(){ if(wifiManager.isWifiEnabled()) return true; return false; } public void openWifi(){ if(!wifiManager.isWifiEnabled()){ wifiManager.setWifiEnabled(true); } } public void closeWifi(){ if(wifiManager.isWifiEnabled()) wifiManager.setWifiEnabled(false); } public List<ScanResult> getWifiList(){ //周围wifi热点信息 每个热点就是ScanResult对象 wifiList=wifiManager.getScanResults(); return wifiList; } public WifiConfiguration createWifiConf(String SSID,String Password,int Type){ //配置连接特定的网络 WifiConfiguration config=new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); config.SSID="\""+SSID+"\""; WifiConfiguration tempConfig=this.isExist(SSID); if(tempConfig!=null){ wifiManager.removeNetwork(tempConfig.networkId); } if(Type==1){ config.wepKeys[0]=""; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex=0; } else if(Type==2){ config.hiddenSSID=true; config.wepKeys[0]="\""+Password+"\""; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; } else { config.preSharedKey = "\"" + Password + "\""; config.hiddenSSID = true; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); // config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); config.status = WifiConfiguration.Status.ENABLED; } return config; } private WifiConfiguration isExist(String SSID){ List<WifiConfiguration> existConfigs=wifiManager.getConfiguredNetworks(); for(WifiConfiguration t:existConfigs){ if(t.SSID.equals("\""+SSID+"\"")) return t; } return null; } public void addNetWork(WifiConfiguration wifiConfiguration){ 连接特定的网络 int wcgId=wifiManager.addNetwork(wifiConfiguration); wifiManager.enableNetwork(wcgId,true); wifiInfo=wifiManager.getConnectionInfo(); } public WifiInfo getWifiInfo(){ wifiInfo=wifiManager.getConnectionInfo(); return wifiInfo; }}
WifiInfo方法介绍
String getBSSID() 返回热点所在网卡的物理地址
int getMacAddress() 返回客户端网卡物理地址
ScanResult方法介绍
属性 String BSSID 返回热点mac的物理地址
0 0
- Wifi涉及到的API
- android游戏开发涉及到的API…
- windows 涉及到的简单socket API函数的用法
- jbpm涉及到的几个重要概念及常用API
- C# 通过SSID连接指定的WIFI 【Managed Wifi API】
- 我做一键WIFI要用到的API
- 关于修改Android标准WIFI的API
- 单卡涉及到的宏
- 涉及到图片展示的
- 研究生论文涉及到的期刊
- 涉及到的权限
- discuz涉及到的问题
- Criter涉及到的查询
- bind9涉及到的文档
- activiti 涉及到的表
- mysql 涉及到的优化
- 在Unicode下,要注意涉及到字符串获取或者存储的API函数的关于buf长度参数的设定
- native wifi api使用方法
- 【剑指offer】之出现次数超过一半的数字
- Centos中使用yum安装java时,没有jps的问题的解决。
- 度量快速开发平台窗体中定时执行实现思路
- 一个完整、安全的PHP用户登录系统
- 织梦系统中“自定义搜索模型不存在”的解决方法
- Wifi涉及到的API
- RGB与16进制色互转
- 【LeetCode】299 Bulls and Cows
- 文本语言模型的参数估计-最大似然估计、MAP及贝叶斯估计
- Contains Duplicate II
- 在Xib中运用Runtime给View加圆角
- C语言读取指定行文本
- 有关js原型的系列方法
- GitLab在windows用户端的使用教程