Can not connect another android device with wifi with android lollipop

五迷三道 提交于 2020-01-07 06:14:05

问题


Hello, I am trying to connect two android device through wifi. here one device was providing hotspot and another device will connect available wifi. In here am using following code to connect with wifi

mainWifi = (WifiManager)device_list.this. getSystemService(Context.WIFI_SERVICE);
mainWifi.setWifiEnabled(true);
mainWifi.startScan();
 WifiConfiguration wifiConfig = new WifiConfiguration();




        wifiConfig.SSID = sr.SSID;
        wifiConfig.status = WifiConfiguration.Status.ENABLED;


        wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
        wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
        wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
        wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
        wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        wifiConfig.priority = 40;


        netId = mainWifi.addNetwork(wifiConfig);

            mainWifi.disconnect();
            mainWifi.enableNetwork(netId, true);
            mainWifi.reconnect();

The above code is working perfect in lower version and i had problem with android lollipop. with android lollipop i can not connect with wifi, it fallback with previous one, so i am waiting for perfect solution for this issue. thank you.


回答1:


I was having the same problem, I fixed this problem by updating the API. Every Operating system kernel Designer provides API, for Application programmers, that changes from time to time.

https://developer.android.com/about/versions/android-5.0.html https://developer.android.com/about/versions/android-5.0-changes.html

May these will help for you also.



来源:https://stackoverflow.com/questions/31537622/can-not-connect-another-android-device-with-wifi-with-android-lollipop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!