如何从 WifiP2pDeviceList 获取 wifi direct 设备名称
How to get wifi direct devices name from WifiP2pDeviceList
我想在执行request peers时获取wi-fi direct名称,这里是我的代码:
if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
Log.d(tag, "success discover the peers ");
if (mManager != null) {
mManager.requestPeers(mChannel, new WifiP2pManager.PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList peers) {
// TODO Auto-generated method stub
if (peers != null) {
if (device.deviceName.equals("ABC")) {
Log.d(tag, "found device!!! ");
Toast.makeText(getApplicationContext(), "FOUND!!", Toast.LENGTH_SHORT).show();
}
}
}
});
} else {
Log.d(tag, "mMaganger == null");
}
}
我想从对等点列表中获取设备名称,以便找到名为 "ABC" 的那个。有什么想法吗?
如果你想要其他设备名称:
wifiP2pManager.requestPeers(wifiChannel, new WifiP2pManager.PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
for (WifiP2pDevice device : wifiP2pDeviceList.getDeviceList())
{
if (device.deviceName.equals("ABC")) Log.d(tag, "found device!!! ");
// device.deviceName
}
}
});
如果您希望在接收器中获取您的设备名称:
if (action.equals(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION))
{
WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
// device.deviceName
}
如果要更改设备名称:
try {
Method method = wifiP2pManager.getClass().getMethod("setDeviceName",
WifiP2pManager.Channel.class, String.class, WifiP2pManager.ActionListener.class);
method.invoke(wifiP2pManager, wifiChannel, "New Device Name", new WifiP2pManager.ActionListener() {
public void onSuccess() {}
public void onFailure(int reason) {}
});
} catch (Exception e) {}
您有 WifiP2pDeviceList
(peers)
对象
在 returns P2p 设备集合(列表)Collection<WifiP2pDevice>
的对等点上调用方法 getDeviceList()
然后遍历 WifiP2pDevice
集合元素,它将包含 deviceName
属性,这正是您所需要的。
参考来自 android 开发人员的 this 培训
希望你能得到它
我想在执行request peers时获取wi-fi direct名称,这里是我的代码:
if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
Log.d(tag, "success discover the peers ");
if (mManager != null) {
mManager.requestPeers(mChannel, new WifiP2pManager.PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList peers) {
// TODO Auto-generated method stub
if (peers != null) {
if (device.deviceName.equals("ABC")) {
Log.d(tag, "found device!!! ");
Toast.makeText(getApplicationContext(), "FOUND!!", Toast.LENGTH_SHORT).show();
}
}
}
});
} else {
Log.d(tag, "mMaganger == null");
}
}
我想从对等点列表中获取设备名称,以便找到名为 "ABC" 的那个。有什么想法吗?
如果你想要其他设备名称:
wifiP2pManager.requestPeers(wifiChannel, new WifiP2pManager.PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
for (WifiP2pDevice device : wifiP2pDeviceList.getDeviceList())
{
if (device.deviceName.equals("ABC")) Log.d(tag, "found device!!! ");
// device.deviceName
}
}
});
如果您希望在接收器中获取您的设备名称:
if (action.equals(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION))
{
WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
// device.deviceName
}
如果要更改设备名称:
try {
Method method = wifiP2pManager.getClass().getMethod("setDeviceName",
WifiP2pManager.Channel.class, String.class, WifiP2pManager.ActionListener.class);
method.invoke(wifiP2pManager, wifiChannel, "New Device Name", new WifiP2pManager.ActionListener() {
public void onSuccess() {}
public void onFailure(int reason) {}
});
} catch (Exception e) {}
您有 WifiP2pDeviceList
(peers)
在 returns P2p 设备集合(列表)Collection<WifiP2pDevice>
getDeviceList()
然后遍历 WifiP2pDevice
集合元素,它将包含 deviceName
属性,这正是您所需要的。
参考来自 android 开发人员的 this 培训
希望你能得到它