Back to project page dissertation-project.
The source code is released under:
MIT License
If you think the Android project dissertation-project listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.fyp.resilience.receiver; //w w w. ja v a 2s .c o m import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.NetworkInfo; import android.net.wifi.p2p.WifiP2pDevice; import android.net.wifi.p2p.WifiP2pManager; import android.net.wifi.p2p.WifiP2pManager.Channel; import android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener; import android.util.Log; /** * A BroadcastReceiver that notifies of important wifi p2p events. */ public class WiFiDirectBroadcastReceiver extends BroadcastReceiver { private static final String TAG = WiFiDirectBroadcastReceiver.class.getSimpleName(); private final WifiP2pManager mP2pManager; private final Channel mChannel; private final Service mService; /** * @param manager WifiP2pManager system service * @param channel Wifi p2p channel * @param activity activity associated with the receiver */ public WiFiDirectBroadcastReceiver(final WifiP2pManager manager, final Channel channel, final Service service) { super(); mP2pManager = manager; mChannel = channel; mService = service; } @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { if (mP2pManager == null) { return; } final NetworkInfo networkInfo = (NetworkInfo) intent .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); if (networkInfo.isConnected()) { // we are connected with the other device, request connection // info to find group owner IP mP2pManager.requestConnectionInfo(mChannel, (ConnectionInfoListener) mService); } else { // It's a disconnect } } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION .equals(action)) { final WifiP2pDevice device = (WifiP2pDevice) intent .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); Log.d(TAG, "Device status -" + device.status); } } }