Can not connect another android device with wifi w

2019-08-23 18:10发布

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.

标签: android wifi
1条回答
仙女界的扛把子
2楼-- · 2019-08-23 19:00

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.

查看更多
登录 后发表回答