检查wifi直连是否已连接

时间:2016-08-23 20:08:36

标签: android andengine

我需要检查我的手机是否连接到wifi直接另一部手机播放,它是在andengine框架上开发的。

  protected Boolean conectadoWifi(){
    WifiP2pManager connectivity=(WifiP2pManager)activity.getSystemService(Context.WIFI_P2P_SERVICE);
    final WifiP2pManager.Channel channel = connectivity.initialize(activity, activity.getMainLooper(), new WifiP2pManager.ChannelListener() {
        @Override
        public void onChannelDisconnected() {
        }
    });

    connectivity.discoverPeers(channel, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            if (WifiP2pManager.WIFI_P2P_STATE_ENABLED == 2) {
                // Wifi Direct mode is enabled
                System.out.println("-----------wifi direct on-");
            }
            if (WifiP2pManager.WIFI_P2P_STATE_DISABLED==1){
                System.out.println("-----------wifi direct off-");
            }
        }
        @Override
        public void onFailure(int i) {
            System.out.println("+++++++++++off wifi++++++++++++++");
        }
    });
        return true;
}

0 个答案:

没有答案