Code example for WifiP2pManager

Methods: initializegetClass

0
				.getSystemService(Context.WIFI_P2P_SERVICE);
		mWifiManager = (WifiManager) context
				.getSystemService(Context.WIFI_SERVICE);
 
		if (mWifiManager.isWifiEnabled()) {
			channel = mWifiP2pManager.initialize(context,
					context.getMainLooper(), null);
			observerList = new ArrayList<WifiDirectManager.ManagerP2pDeivce>();
		} 
		if (flag) {
			setDeviceName( 
					mWifiP2pManager,
					channel,
					WiFiNameEncryption.generateWiFiName("DreamLink" 
							+ UserHelper.getUserName(context)), null);
		} 
	} 
 
	@SuppressLint({ "NewApi", "NewApi" }) 
	public void discover() { 
		mWifiP2pManager.discoverPeers(channel, null);
	} 
 
	private void setDeviceName(WifiP2pManager manager, Channel channel,
			String name, ActionListener listener) {
		try { 
			Method method = manager.getClass().getMethod("setDeviceName",
					Channel.class, String.class, ActionListener.class);
			method.invoke(manager, channel, name, listener);
		} catch (Exception e) {
			Log.e(TAG, "setDeviceName fail: " + e);
		}