【发布时间】:2015-08-26 19:32:36
【问题描述】:
我正在尝试制作一个与我的电脑中的热点通信的应用程序。我能够连接到热点,但我无法弄清楚如何在 android 中发送和接收数据。这是我现在在我的应用程序中的代码。
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// setup a wifi configuration
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"pigo\"";
wc.preSharedKey = "\"12345678\"";
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
// connect to and enable the connection
int netId = wifiManager.addNetwork(wc);
wifiManager.enableNetwork(netId, true);
wifiManager.setWifiEnabled(true);
stepinfo.setText("Initiating Connection . . .");
我查看了其他类似的问题,但我的应用似乎没有任何效果。
【问题讨论】:
-
电脑中的热点?请解释一下如何在电脑上制作热点?
-
您的代码使用 wifi 管理器执行某些操作。好的。但是您到底想向什么发送数据?
-
@greenapps 在管理员模式下使用 cmd step1) netsh wlan set hostsnetwork mode=allow ssid=pigo key=12345678 step2) netsh wlan start hostingnetwork
-
对不起,我不明白。
标签: java android android-wifi