WifiP2pManager.initialize 返回 null。我正在使用 Droid 4,Android 版本 4.0.4,并使用 API 级别 14 构建了我的应用程序。
...
_p2pChannel = _p2pManager.initialize(this, getMainLooper(), new WifiP2pManager.ChannelListener() {
@Override
public void onChannelDisconnected() {
Log.e(TAG, "Peer-to-peer manager channel disconnected.");
//TODO: Manage the re-creation of the channel
_p2pChannel = null;
}
});
if (_p2pChannel == null) {
Log.e(TAG, "P2P Manager failed to initialize.");
return;
}
....
Android 清单具有:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:name="android.hardware.wifi.direct"
android:required="true"/>