Code example for WifiP2pManager

Methods: discoverPeers, initialize

0
			} 
		} 
 
		if (this.wifiChannel == null) {
			 
			this.wifiChannel = this.wifip2pManager.initialize(this, getMainLooper(), null);
			 
			if (this.wifiChannel == null) {
				return UNABLE_TO_ACCESS_WIFI_CHANNEL;
			} 
		} 
 
		// Create intent filter and register Wifi broadcast receiver to receive broadcast events 
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
		intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
		intentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
 
		if (this.broadcastReceiver == null) {
			this.broadcastReceiver = new WifiP2pBroadcastReceiver(this.wifip2pManager, this.wifiChannel, this);
		} 
		registerReceiver(this.broadcastReceiver, intentFilter);
 
		return WIFI_ACCESS_SUCCESSFUL;
	} 
 
	private void releaseWifiResources() { 
		 
		// Release all Wifi resources 
		if (this.wifip2pManager != null) {
			this.wifip2pManager = null;
		} 
 
		if (this.wifiChannel != null) {
			this.wifiChannel = null;
		} 
 
		// Unregister broadcast receiver 
		unregisterReceiver(this.broadcastReceiver);
		if (this.broadcastReceiver != null) {
			this.broadcastReceiver = null;
		} 
	} 
 
	private void startPeerDiscovery() { 
		 
		this.wifip2pManager.discoverPeers(this.wifiChannel, this.broadcastReceiver);
	} 
 
	@Override 
	protected void onResume() { 
		super.onResume();