public class mainactivity extends activity else
ht = new handlerthread("ht");
ht.start();
mhandler = new myhandler();
message msg = mhandler.obtainmessage();
bundle bundle = new bundle();
bundle.putboolean("key1", true);
msg.setdata(bundle);
msg.sendtotarget();
//scan wifi
listscanresult = mwifimanager.getscanresults();
log.i("ntb", "scanresult size = " + scanresult.size());
for (scanresult res : scanresult)
//get current wifi info
wifiinfo info = mwifimanager.getconnectioninfo();
log.i("ntb", info.getssid());
log.i("ntb", "oncreate finish"); }
/*這裡以handler去處理耗時操作*/
private class myhandler extends handler
public myhandler(looper looper)
@override
public void handlemessage(message msg) catch (interruptedexception e)
super.handlemessage(msg);
bundle b = msg.getdata();
if (b.getboolean("key1") == true)
}} ///
/*下面分三種情況,分別是沒有密碼,wep模式,wpa模式,去建立對應的wificonfiguration物件*/
private wificonfiguration createwifiinfo (string ssid, string password, int type)
if(type == 1) //wificipher_nopass
if(type == 2) //wificipher_wep
else
}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;
config.status = wificonfiguration.status.enabled;
config.bssid = "4c:60:de:3e:e7:b4";
} if(type == 3) //wificipher_wpa
return config; }
/ public void addnetwork(wificonfiguration wcg)
//這裡我先斷開,再使能,然後重新連線,正常的話android應該會主動去連線我配置好的熱點
// mwifimanager.disconnect();
boolean b = mwifimanager.enablenetwork(wcgid, true);
boolean c = mwifimanager.reassociate();
system.out.println("a--" + wcgid);
system.out.println("b--" + b);
system.out.println("c--" + c);
} /
private wificonfiguration i***sits(string ssid)
}
return null;
} @override
public boolean oncreateoptionsmenu(menu menu)
}
android 自動連線WiFi
很久沒有寫部落格了,今天記錄下做專案中發現的問題,關於自動連線wifi問題,本來在網上找了許多,發現測試下來不太好用,於是找了找原因,再次記錄一下。先說工具類吧,包含了許多,網上也能找到類似的 public class wifiadmin public void setmwifimanager wi...
Android 自動連線藍芽
藍芽是手機和智慧型硬體通訊常用的方式,藍芽通訊可分為傳統藍芽和低功耗藍芽 ble 其中ble的連線斷開等操作可以通過android sdk中提供的api進行操作,而傳統藍芽部分sdk並沒有提供相關的api進行連線斷開,只能使用者自己通過手機的設定介面連線藍芽。那麼我們如何做到在 中自動連線傳統藍芽呢...
基於AppDomain的外掛程式開發 自動載入(三)
前面已經得到了熱插拔的外掛程式原型,這次討論如果外掛程式是服務提供者怎麼辦?我能想到的,需要在起動時載入所有外掛程式 然後在外掛程式變動時,及時解除安裝舊的外掛程式,載入新的外掛程式。如果有新外掛程式放在目錄中,需要馬上載入新的外掛程式。如果外掛程式被刪除,我們要把對應的服務也移除。最終使用時,如下...