Android WifiP2pManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android WifiP2pManager class.

This code example shows how to use the following methods:discoverPeers, requestPeers, stopPeerDiscovery, getClass
		} 
	} 
 
	@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);
		} 
	} 
 
	/** 

4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:initialize
        mContext = context;
        mCheckBox = checkBox;
 
        mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
        if (mWifiP2pManager != null) {
            mChannel = mWifiP2pManager.initialize(mContext, mContext.getMainLooper(), null);
            if (mChannel == null) {
                //Failure to set up connection 
                Log.e(TAG, "Failed to set up connection with wifi p2p service");
                mWifiP2pManager = null;
                mCheckBox.setEnabled(false);
            } 
        } else { 
            Log.e(TAG, "mWifiP2pManager is null!");
        } 
        mIntentFilter = new IntentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
 
    } 
 
    public void resume() { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
	} 
 
	private void refreshPeers() { 
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
			Log.i(TAG, "Request peers");
			wifiMgr.requestPeers(channel, discoveryListener);
		} 
	} 
	 
	@Override 
	public void onChannelDisconnected() { 
		Log.e(TAG, "Error Channel disconnected");
	} 
 
	private class WifiReceiver extends BroadcastReceiver {
		 
		@Override 
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
	@Override 
	public void searchForLinks() { 
		peerListener.devices.clear();
		searchingForLinks = true;
		if (manager != null && channel != null) {
			manager.requestPeers(channel, peerListener);
		} 
	} 
	 
 
	/** 
	 * {@inheritDoc} 
	 */ 
	@Override 
	public void haltConnectionDiscovery() { 
		manager.stopPeerDiscovery(channel, null);
		manager.cancelConnect(channel, null);
	} 
 
	 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
				discoverPeers(); 
			} else { 
				System.out.println("Wifi disabled!");
			} 
		} else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
			mManager.requestPeers(mChannel, myPeerListListener);
		} 
		else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
 
			connectionChanged(intent);
			// Respond to new connection or disconnections 
		} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
			// Respond to this device's wifi state changing 
		} 
	} 
 
	private void discoverPeers() { 
		mManager.discoverPeers(mChannel,new WifiP2pManager.ActionListener() {
			@Override 
			public void onSuccess() { 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
 
            // request available peers from the wifi p2p manager. This is an 
            // asynchronous call and the calling activity is notified with a 
            // callback on PeerListListener.onPeersAvailable() 
            if (manager != null) {
                manager.requestPeers(channel, mNetInfManager);
            } 
            Log.d(TAG, "P2P peers changed");
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
 
            if (manager == null) {
                return; 
            } 
 
            NetworkInfo networkInfo = (NetworkInfo) intent
                    .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
 
            if (networkInfo.isConnected()) {
 
                // we are connected with the other device, request connection 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:initialize
	 */ 
	public static boolean getP2pInfo(Context mContext){
		WifiP2pManager p2pmgr = (WifiP2pManager)mContext.getSystemService(Context.WIFI_P2P_SERVICE);
		//if(manager==null) 
		//	manager= new WifiUtil(mContext, null); 
		p2pmgr.initialize(mContext, null, null);
		//p2pmgr 
		 
		return false; 
		 
	} 
	 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
 
            // request available peers from the wifi p2p manager. This is an 
            // asynchronous call and the calling activity is notified with a 
            // callback on PeerListListener.onPeersAvailable() 
            if (manager != null) {
                manager.requestPeers(channel, (PeerListListener) this);
            } 
            Log.d(TAG, "P2P peers changed");
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
 
            if (manager == null) {
                return; 
            } 
 
            NetworkInfo networkInfo = (NetworkInfo) intent
                    .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
 
            if (networkInfo.isConnected()) {
 
                // we are connected with the other device, request connection 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestGroupInfo
	} 
 
	@Override 
	public void onSuccess() { 
		Log.e(TAG, "Create group succeeds.");
		wifiDirectManager.requestGroupInfo(wifiDirectChannel, this);
	} 
 
	@Override 
	public void onGroupInfoAvailable(WifiP2pGroup group) {
		if (isSensing == false)
			return; 
		Log.i(TAG, "***wifi direct group info available!");
		if (group == null) {
			new Thread(new Runnable() {
 
				@Override 
				public void run() { 
					try { 
						Thread.sleep(10 * 1000);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:requestPeers
 
            // request available peers from the wifi p2p manager. This is an 
            // asynchronous call and the calling activity is notified with a 
            // callback on PeerListListener.onPeersAvailable() 
            if (manager != null) {
                manager.requestPeers(channel, activity.getfDevList());
            } 
            Log.d("Test", "P2P peers changed");
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
 
            if (manager == null) {
                return; 
            } 
 
            NetworkInfo networkInfo = (NetworkInfo) intent
                    .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
 
            if (networkInfo.isConnected()) {
 
                // we are connected with the other device, request connection 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android WifiP2pManager Questions & Answers:

See Code Examples for Android WifiP2pManager Methods: