使用WiFi direct Android以编程方式创建热点
我一直在尝试在Android中使用WiFi Direct创建WiFi热点。在谷歌和安卓开发者论坛上搜索后,我发现这可以通过使用WiFi direct Android以编程方式创建热点,android,wifi-direct,wifip2p,Android,Wifi Direct,Wifip2p,我一直在尝试在Android中使用WiFi Direct创建WiFi热点。在谷歌和安卓开发者论坛上搜索后,我发现这可以通过WifiP2pManager实现。我已经能够通过以下代码创建一个组并生成其凭据: WifiManager wifi =(WifiManager) getApplicationContext().getSystemService("wifi"); IntentFilter intentFilter = new IntentFilter(); intent
WifiP2pManager
实现。我已经能够通过以下代码创建一个组并生成其凭据:
WifiManager wifi =(WifiManager) getApplicationContext().getSystemService("wifi");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
static Channel channel = manager.initialize(this, getMainLooper(), this);
registerReceiver(p2pRecv, intentFilter);
manager.createGroup(channel, null);
manager.requestGroupInfo(channel, new GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
if (group != null && group.isGroupOwner()) {
String groupName = group.getNetworkName();
String groupPassword = group.getPassphrase();
txtHotspotName.setText(groupName + "|||" + groupPassword);
}
}
});
一旦生成凭据,附近的任何设备都可以使用这些凭据进行连接,但连接后,即使在组所有者设备上连接了WiFi,internet也无法在连接的设备上工作。有没有办法让互联网在连接的设备上工作