连接到wifi,但在手机中看不到任何东西

时间:2016-05-01 08:44:03

标签: android android-studio wifi

我正在尝试连接到WIFI点, 当我运行代码并查看日志时,我确实得到了“连接到wifi点” 记录消息,所以理论上我是连接的, 但在我的手机中,我没有连接标志, 它看起来好像我没有连接到WIFI, 这可能是什么问题?

我正在使用此功能连接到远程WIFI点

public void connectToNetwork (String ssidName, String netPassword) {

        Log.d("mtAppLogs", "initlizing search");

        String networkSSID = ssidName;
        String networkPass = netPassword;

        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + networkSSID + "\"";   // Please note the quotes. String should contain
        conf.preSharedKey = "\""+ networkPass +"\"";

        WifiManager wifiManager = (WifiManager)getApplication().getSystemService(Context.WIFI_SERVICE);
        wifiManager.addNetwork(conf);

        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        for( WifiConfiguration i : list ) {
            Log.d("mtAppLogs", "initlizing wifi Point");
            if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
                Log.d("mtAppLogs", "foundWifiPiont");
                wifiManager.disconnect();
                wifiManager.enableNetwork(i.networkId, true);
                wifiManager.reconnect();
                Log.d("mtAppLogs", "connected to wifi point");
                break;
            }
        }

    }

我正在为我的班级使用这些权限&gt;

  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

0 个答案:

没有答案