gpt4 book ai didi

java - 如何从 WifiP2pDeviceList 获取 wifi direct 设备名称

转载 作者:太空宇宙 更新时间:2023-11-03 13:19:49 24 4
gpt4 key购买 nike

我想在执行请求对等点时获取 wi-fi 直连名称,这是我的代码:

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) {}

关于java - 如何从 WifiP2pDeviceList 获取 wifi direct 设备名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30256505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com