我想在两个 Android 设备之间通过热点交换数据。我已尝试正确连接。
1st。我创建了可移植热点:
网络 SSID - my_hotspot安全 - WPA PSK
密码-密码
第二。我正在尝试在应用程序启动时进行连接。这是我的代码
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.wepKeys[0] = "\"" + networkPass + "\"";
conf.wepTxKeyIndex = 0;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
conf.preSharedKey = "\""+ networkPass +"\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
int res = mWifiManager.addNetwork(conf);
boolean b = setWifiApEnabled(null, true);
我认为它是不成功的。然后我尝试通过套接字发送数据。我从 JavaCodeGeeks 中学到了.我配置了SERVER_IP 192.168.49.1,SERVER_PORT:8888。
如何使用热点在两个 Android 设备之间正确通信?
提前致谢。
最佳答案
您为什么不使用 Wi-Fi Direct?它是一种 p2p 协议(protocol)。您无需热点即可在两台 Android 设备之间共享数据。它使用 android.net.wifi.p2p 包。
Wi-Fi peer-to-peer (P2P) allows Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi without an intermediate access point (Android's Wi-Fi P2P framework complies with the Wi-Fi Alliance's Wi-Fi Direct™ certification program). Using these APIs, you can discover and connect to other devices when each device supports Wi-Fi P2P, then communicate over a speedy connection across distances much longer than a Bluetooth connection. This is useful for applications that share data among users, such as a multiplayer game or a photo sharing application.
您可以在 Android 开发者网站上找到有关此技术的更多信息。以下是一些有用的链接:
关于android - 通过热点在两个 Android 设备之间进行数据交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21926158/