在Android上没有工作的WiFi直正常 [英] WiFi Direct on Android not working properly
问题描述
我想开发使用WiFi直接在安卓果冻豆4.1.1的应用程序。如果P2P启用我immedialtely叫
I am trying to develop an app using wifi direct in android Jelly Bean 4.1.1. If p2p is enabled I immedialtely call
mManager.discoverPeers(mChannel, actionListener);
之后,我收到一个电话回
After that I am getting a call back to the
onPeersAvailable(WifiP2pDeviceList)
我有2个三星(谷歌)的Nexus设备和WiFi直接测试已开启两个。但这个回调将返回同行的空单。但是,例如,如果我点击搜索同行的默认无线网络直接接口按钮immedialtely第二装置触发
I am testing with 2 Samsung(Google) Nexus device and wifi direct is turned on on both. But this call back is returning an empty list of peers. But for instance if I click on the Search Peers button on the default wifi direct interface immedialtely the second device fires the
WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION
WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION
和这依次调用
onPeersAvailable(WifiP2pDeviceList peers)
因为我要求使用同行针对该事件
as I am requesting for peers for that event using
mManager.requestPeers(mChannel, WifiDirectService.this);
这时候我就能看到同龄人。我看到这对于许多次。
This time I will be able to see the peers. I am seeing this for a number of times.
可能是什么可能的原因? 谢谢
What could be the possible reason? Thanks
推荐答案
您应该使用发现peermethod:
You should use the Discovering peermethod:
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
...
}
@Override
public void onFailure(int reasonCode) {
...
}
});
如果发现过程成功,并检测同行,系统广播WIFI_P2P_PEERS_CHANGED_ACTION意图,你可以在一个广播接收器监听获得同龄人的名单。当你的应用程序收到WIFI_P2P_PEERS_CHANGED_ACTION意图,您可以要求发现的对等与requestPeers)的列表(
If the discovery process succeeds and detects peers, the system broadcasts the WIFI_P2P_PEERS_CHANGED_ACTION intent, which you can listen for in a broadcast receiver to obtain a list of peers. When your application receives the WIFI_P2P_PEERS_CHANGED_ACTION intent, you can request a list of the discovered peers with requestPeers().
有关完整的示例,请查看:的http://developer.android.com/guide/topics/connectivity/wifip2p.html#discovering
For the full example, please check: http://developer.android.com/guide/topics/connectivity/wifip2p.html#discovering
这篇关于在Android上没有工作的WiFi直正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!