整理自动连接指定wifi无密码方式错误解决办法Word文档格式.docx
《整理自动连接指定wifi无密码方式错误解决办法Word文档格式.docx》由会员分享,可在线阅读,更多相关《整理自动连接指定wifi无密码方式错误解决办法Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
//扫描出的网络连接列表
privateList<
ScanResult>
mWifiList;
//网络连接列表
WifiConfiguration>
mWifiConfiguration;
//定义一个WifiLock
WifiLockmWifiLock;
*构造器
publicOpenWifi(Contextcontext){
//取得WifiManager对象
mWifiManager=(WifiManager)context
.getSystemService(Context.WIFI_SERVICE);
//取得WifiInfo对象
mWifiInfo=mWifiManager.getConnectionInfo();
}
*打开WIFI
publicvoidopenWifi(){
if(!
mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(true);
*关闭WIFI
publicvoidcloseWifi(){
if(mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(false);
*检查当前WIFI状态
*@return
publicintcheckState(){
returnmWifiManager.getWifiState();
*锁定WifiLock
publicvoidacquireWifiLock(){
mWifiLock.acquire();
*解锁WifiLock
publicvoidreleaseWifiLock(){
//判断时候锁定
if(mWifiLock.isHeld()){
*创建一个WifiLock
publicvoidcreatWifiLock(){
mWifiLock=mWifiManager.createWifiLock("
Test"
);
*得到配置好的网络
publicList<
getConfiguration(){
returnmWifiConfiguration;
*提供一个外部接口,传入要连接的无线网
*@paramssid
*@parampassword
*@paramtype
publicvoidconnect(Stringssid,Stringpassword,inttype){
Threadthread=newThread(newConnectRunnable(ssid,password,type));
thread.start();
classConnectRunnableimplementsRunnable{
privatestaticfinalStringTAG="
ConnectRunnable===="
;
privateStringssid;
privateStringpassword;
privateinttype;
publicConnectRunnable(Stringssid,Stringpassword,inttype){
this.ssid=ssid;
this.password=password;
this.type=type;
@Override
publicvoidrun(){
//打开wifi
openWifi();
//开启wifi功能需要一段时间(我在手机上测试一般需要1-3秒左右),所以要等到wifi
//状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句
while(mWifiManager.getWifiState()==WifiManager.WIFI_STATE_ENABLING){
try{
//为了避免程序一直while循环,让它睡个100毫秒检测……
Thread.sleep(100);
}catch(InterruptedExceptionie){
WifiConfigurationwifiConfig=CreateWifiInfo(ssid,password,type);
//
if(wifiConfig==null){
Log.d(TAG,"
wifiConfigisnull!
"
return;
WifiConfigurationtempConfig=IsExsits(ssid);
if(tempConfig!
=null){
mWifiManager.removeNetwork(tempCworkId);
intnetID=mWifiManager.addNetwork(wifiConfig);
booleanenabled=mWifiManager.enableNetwork(netID,true);
enableNetworkstatusenable="
+enabled);
booleanconnected=mWifiManager.reconnect();
enableNetworkconnected="
+connected);
*指定配置好的网络进行连接
*@paramindex
publicvoidconnectConfiguration(intindex){
//索引大于配置好的网络索引返回
if(index>
mWifiConfiguration.size()){
//连接配置好的指定ID的网络
mWifiManager.enableNetwork(mWifiConfiguration.get(index).networkId,
true);
publicvoidstartScan(){
mWifiManager.startScan();
//得到扫描结果
mWifiList=mWifiManager.getScanResults();
//得到配置好的网络连接
mWifiConfiguration=mWifiManager.getConfiguredNetworks();
*得到网络列表
getWifiList(){
returnmWifiList;
*查看扫描结果
publicStringBuilderlookUpScan(){
StringBuilderstringBuilder=newStringBuilder();
for(inti=0;
i<
mWifiList.size();
i++){
stringBuilder
.append("
Index_"
+newInteger(i+1).toString()+"
:
//将ScanResult信息转换成一个字符串包
//其中把包括:
BSSID、SSID、capabilities、frequency、level
stringBuilder.append((mWifiList.get(i)).toString());
stringBuilder.append("
/n"
returnstringBuilder;
*得到MAC地址
publicStringgetMacAddress(){
return(mWifiInfo==null)?
"
NULL"
:
mWifiInfo.getMacAddress();
*得到接入点的BSSID
publicStringgetBSSID(){
mWifiInfo.getBSSID();
*得到IP地址
publicintgetIPAddress(){
0:
mWifiInfo.getIpAddress();
*得到连接的ID
publicintgetNetworkId(){
mWifiInfo.getNetworkId();
*得到WifiInfo的所有信息包
publicStringgetWifiInfo(){
mWifiInfo.toString();
*添加一个网络并连接
*@paramwcg
publicvoidaddNetwork(WifiConfigurationwcg){
intwcgID=mWifiManager.addNetwork(wcg);
booleanb=mWifiManager.enableNetwork(wcgID,true);
System.out.println("
a--"
+wcgID);
b--"
+b);
*断开指定ID的网络
*@paramnetId
publicvoiddisconnectWifi(intnetId){
mWifiManager.disableNetwork(netId);
mWifiManager.disconnect();
*获取SSID(网络名称)
publicStringgetSSID(){
null:
mWifiInfo.getSSID();
*然后是一个实际应用方法,只验证过没有密码的情况:
*@paramSSID
*@paramPassword
*@paramType
//分为三种情况:
1没有密码2用wep加密3用wpa加密
publicWifiConfigurationCreateWifiInfo(StringSSID,StringPassword,
intType){
WifiConfigurationconfig=newWifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID="
\"
+SSID+"
/*
*WifiConfigurationtempConfig=this.IsExsits(SSID);
if(tempConfig!
=
*null){mWifiManager.removeNetwork(tempCworkId);
}
if(Type==1)//WIFICIPHER_NOPASS
{
//config.wepKeys[0]="
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
//config.wepTxKeyIndex=0;
//
网上的方法大都写了红色部分,一定要删掉这两句才能连接上
if(Type==2)//WIFICIPHER_WEP
config.hiddenSSID=true;
config.wepKeys[0]="
+Password+"
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.wepTxKeyIndex=0;
if(Type==3)//WIFICIPHER_WPA
config.preSharedKey="
.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.TKIP);
//config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status=WifiConfiguration.Status.ENABLED;
returnconfig;
1.规划环境影响评价的报审
*查看以前是否也配置过这个网络
(二)安全评价的基本原则
(3)介绍评价对象的选址、总图布置、水文情况、地质条件、工业园区规划、生产规模、工艺流程、功能分布、主要设施、设备、装置、主要原材料、产品(中间产品)、经济技术指标、公用工程及辅助设施、人流、物流等概况。
privateWifiConfigurationIsExsits(StringSSID){
List<
existingConfigs=mWifiManager
.getConfiguredNetworks();
考试情况分析if(existingConfigs==null){
returnnull;
4.环境影响评价工作等级的调整}else{
(1)生产力变动法Log.e(HomeActivity.TAG,"
existingConfigs=="
+existingConfigs);
1.直接市场评估法
for(WifiConfigurationexistingConfig:
existingConfigs){
if(existingConfig.SSID.equals("
)){
returnexistingConfig;
1)地方环境标准是对国家环境标准的补充和完善。
在执行上,地方环境标准优先于国家环境标准。
[答疑编号502334050101]}
规划环境影响的跟踪评价应当包括下列内容: