如何解决WIFI Direct:createGroup with config 总是失败,报错
当我调用此方法 createGroup(WifiP2pManager.Channel c,WifiP2pManager.ActionListener listener)
时,它起作用了。
但我想设置一些配置,所以我调用 createGroup(WifiP2pManager.Channel c,WifiP2pConfig config,WifiP2pManager.ActionListener listener)
,它出错了。
这是我的代码:
WifiP2pConfig config = new WifiP2pConfig.Builder()
.enablePersistentMode(true)
.setNetworkName("DIRECT-xy-MEIZU 16s")
.setPassphrase("wanghui123456")
.setDeviceAddress(MacAddress.fromString("72:8E:BA:03:F1:16"))
.setGroupOperatingBand(WifiP2pConfig.GROUP_OWNER_BAND_5GHZ)
.build();
Log.d(TAG,"onCreateBackgroundJob: " + config.describeContents() + config.toString());
if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions,and then overriding
// public void onRequestPermissionsResult(int requestCode,String[] permissions,// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
manager.createGroup(channel,config,new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG,"onSuccess: ");
}
@Override
public void onFailure(int reason) {
Log.d(TAG,"onFailure: " + reason);
}
});
我得到的日志是 onFailure: 0
错误
在 API 级别 14 中添加
public static final int ERROR
通过 ActionListener#onFailure。表示操作因内部错误而失败。
常量值:0 (0x00000000))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。