i have created simple application detect , connect other wifi devices. able connect other devices not able connect internet using connected wifi. wants use connected wifi browsing.
my connection code is:
public boolean connecttonetwork(string sbssid, int isecuritytype, string ssecuritykey, string sssid) { isecuritytype = 1; // context variable context tmpcontext = getapplicationcontext(); // getcontexteapplication(); // , wifi manager object wifimanager tmpmanager = (wifimanager) tmpcontext .getsystemservice(android.content.context.wifi_service); // init variable process current wifi settings wificonfiguration tmpconfig; // checks if wifi network want connect not // known // retrieves list of configured networks list<wificonfiguration> listconfig = tmpmanager.getconfigurednetworks(); tmpconfig = new wificonfiguration(); // loop on if (listconfig != null) { (int = 0; < listconfig.size(); i++) { // element config in processing variable tmpconfig = listconfig.get(i); // checks if there if (tmpconfig.bssid != null) { if (tmpconfig.bssid.equalsignorecase(sbssid)) { // found: returns result of trying enabling return tmpmanager.enablenetwork(tmpconfig.networkid, true); } } } } // it's new network, need set // creates new wificonfiguration object // set needed information tmpconfig.bssid = sbssid; tmpconfig.ssid = sssid; tmpconfig.priority = 1; switch (isecuritytype) { // wpa case 1: tmpconfig.presharedkey = ssecuritykey; break; // wep case 2: tmpconfig.wepkeys[0] = ssecuritykey; tmpconfig.weptxkeyindex = 0; break; // none case 3: break; } // connection status tmpconfig.status = wificonfiguration.status.enabled; // adds new configuration int netid = tmpmanager.addnetwork(tmpconfig); // attempt connect network, return result return tmpmanager.enablenetwork(netid, true); }
you have give app internet permission. add following manifest:
<uses-permission android:name="android.permission.internet" /> see here list of permissions available.
Comments
Post a Comment