public void discoverpeers(View v) {
wifiP2pManager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Toast.makeText(getApplicationContext(), "Peer Discovery Successful", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(int reason) {
Toast.makeText(WiDiActivity.this, reason + "", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Peer Discovery Failed", Toast.LENGTH_LONG).show();
}
});
}
对等点发现失败,原因= 0.我使用的Android版本是6.0。该代码在版本低于6.0的其他设备上运行完美 我也打开了我的位置设置。 我使用了以下许可:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />