在Android上使用Wi-Fi创建P2P连接



所以我正在尝试在安卓上创建p2p连接工作。下面的代码是API上提供的代码,对我来说没有意义。我觉得 mManager 必须有一个类型,但没有给出类型。我该如何使它工作?

链接到 API:http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html

@Override
Channel mChannel;
public void onCreate(Bundle savedInstanceState) {
    ....
    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    mChannel = mManager.initialize(this, getMainLooper(), null);
}

我有一种感觉,你导入了错误的频道。您可能已导入

java.nio.Channels.Channel

当你想要的那个是

android.net.wifi.p2p.WifiP2pManager.Channel

希望这有帮助。

我在项目中使用了alljoin。此 API 非常成功地传达了两个设备。

您要查找的类型是:

WifiP2pManager manager;

最新更新