Code example for WifiP2pManager

Methods: requestPeers

0
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			 
			// Peers list has changed 
			if (action.equals(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION)) {
				mManager.requestPeers(mChannel, MainActivity.this);
			} 
			// Wifi P2p state changed 
			else if (action.equals(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION)) {
				// Check if Wifi P2p is on/supported 
				int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
				if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
					// Wifi P2p is enabled 
					mManager.discoverPeers(mChannel, MainActivity.this);
				} else { 
					// Wifi P2p is disabled 
					Toast.makeText(MainActivity.this, "Wifi P2p disabled.", Toast.LENGTH_LONG).show();
				} 
			}  
		}		 
	}