我很生气,我正在学习 Wifi 点对点教程:
https://developer.android.com/guide/topics/connectivity/wifip2p.html
为了找到错误,我在 Activity 的 onCreate()
中尝试了很多方法,而我的最后一个测试就是:
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
manager.toString();
我发现我的经理始终为空。我不明白为什么,我的 API 级别是正确的,并且我在互联网上没有发现有关 WifiP2pManager
和 getSystemService
的任何问题。我错过了什么?
AndroidManifest.xml
<uses-sdk android:minSdkVersion="14"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
最佳答案
我也遇到了同样的问题。每次我通过模拟器运行代码时,都会收到一条错误消息,指出对象为空,但当我在 Nexus(真实设备)中运行代码时,没有错误并且对象不为空。我认为原因是模拟器不支持p2p,而真实设备支持。希望我有所帮助。
关于android - WifiP2pManager 空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46827368/