WiFi Direct设备与其他Android设备的连接 [英] WiFi Direct device connection with other Android devices

查看:347
本文介绍了WiFi Direct设备与其他Android设备的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将启用了WiFi Direct的设备连接到其他没有WiFi Direct功能但支持WiFi热点连接的设备吗? WiFi是否直接使用专用硬件在两个设备上都存在?在这种情况下,网络发现会起作用吗?

Can I connect a WiFi Direct enabled device to any other device which doesn't have WiFi Direct feature but supports WiFi hotspot connection? Does WiFi direct uses specialized hardware to be present on both devices? Will network discovery work in such cases?

推荐答案

有可能。代码摘自我在Droidcon UK 2013上的一次演讲。

It is possible. Code taken from a talk I gave at Droidcon UK 2013.

您需要调用 createGroup(WifiP2pManager.Channel c,WifiP2pManager.ActionListener listener) WifiP2pManager类的方法。这将创建一个支持旧版Wi-Fi连接的Wi-Fi Direct组。

You need to call the createGroup(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener) method of the WifiP2pManager class. This will create a Wi-Fi Direct group that supports legacy Wi-Fi connections.

在通话之前,您需要注册一个类似于以下内容的广播接收器:

Prior to the call, you need to register a broadcast receiver similar to this:

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals
            (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION)){
            wifiP2pManager.requestGroupInfo(channel,
                new WifiP2pManager.GroupInfoListener() {
                @Override
                public void onGroupInfoAvailable(WifiP2pGroup group) {
                    if(group != null){
                        // clients require these
                        String ssid = group.getNetworkName(),
                        String passphrase = group.getPassphrase() 
                    }
                }
            });
        }
    }
};

其他设备随后可以使用Wi-Fi连接到Wi-Fi Direct设备有ssid和密码。

The other devices can then use Wi-Fi to connect to the Wi-Fi Direct device, once they have the ssid and passphrase.

这篇关于WiFi Direct设备与其他Android设备的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆