获取无线网络中的连接设备

时间:2015-02-19 13:58:26

标签: java android

您好 我搜索如何检测无线网络中连接的设备。

 public class WiFiBroadcastReceiver extends BroadcastReceiver {
    private WifiP2pManager manager;
    private Channel channel;
    private WifiDirect activity;
    private PeerListListener myPeerListListener;
    public WiFiBroadcastReceiver(WifiP2pManager manager, Channel channel, WifiDirect activity){
        super();
        this.manager = manager;
        this.channel = channel;
        this.activity = activity;
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
               Toast.makeText(context, " Wifi P2P is enabled", Toast.LENGTH_LONG).show();
            } else {
              Toast.makeText(context, " Wi-Fi P2P is not enabled", Toast.LENGTH_LONG).show();
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
            Toast.makeText(context, "Lis of devices", Toast.LENGTH_LONG).show();
            if (manager != null) {
                manager.requestPeers(channel, myPeerListListener);
            }
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        }
    }
}

但是这段代码显示了一个包含消息的Toast:Wifi P2P已启用 问题是什么。 请帮帮我。

0 个答案:

没有答案