我将通过 wifip2pmanager 在 android 中启动一个项目。似乎频道已成功创建(“初始化”)。但是对于下一步,我的代码不起作用(“discoverPeers 或 creategroup”)。下面的代码有什么问题吗?
public class MainActivity extends Activity {
WifiP2pManager wifiMgr;
Channel channel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifiMgr = (WifiP2pManager)getSystemService(Context.WIFI_P2P_SERVICE);
channel = wifiMgr.initialize(this,getMainLooper(),null);
wifiMgr.discoverPeers(channel, new ActionListener(){
@Override
public void onFailure(int arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "discover fail."+arg0,
Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "discover succ.",
Toast.LENGTH_SHORT).show();
}
});
}
}