问题描述
我在我的应用程序中创建的WiFi AP编程。不要当新设备连接到我的AP我得到任何广播。
I am creating WiFi AP programmatically in my application. Do i get any broadcast when new devices connect to my AP.
我知道我们可以从的/ proc /净/ ARP 获取所连接设备的列表中,但我需要一个回调时,有一个新的连接。
I know we can get the list of the connected devices from the /proc/net/arp but i need a callback when there is a new connection.
任何帮助是AP preciated。
Any help is appreciated.
推荐答案
如果您不需要使用AP来连接到互联网,但只是在一个局域网通信,可以创建WifiP2pManager例如createGroup一个P2P组并听取WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION与广播接收机。
If you don't need to use the AP to connect to the internet but just to communicate in a LAN, you can create a P2P group with WifiP2pManager instance createGroup and listen to WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION with a broadcast receiver.
这样的:
if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)){
NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if (networkInfo.isConnected()) {
Manager.requestConnectionInfo(mChannel, new WifiP2pManager.ConnectionInfoListener(){
@Override
public void onConnectionInfoAvailable(final WifiP2pInfo info) {
if (info.isGroupOwner) {
mManager.requestGroupInfo(mChannel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup group) {
//This is the size you want
group.getClientList().size();
}
});
}
}
});
}
}
有关更详细的看一下:
For more detail look at:http://developer.android.com/guide/topics/connectivity/wifip2p.html
这篇关于回调的设备连接到WiFi热点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!