Java Code Examples for android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_ENABLED

The following examples show how to use android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_ENABLED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityManageP2P.java    From nfcspy with GNU General Public License v3.0 6 votes vote down vote up
void handleBroadcast(Intent intent) {
	closeProgressDialog();

	final String action = intent.getAction();
	if (WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
		int state = intent.getIntExtra(EXTRA_WIFI_STATE, -1);
		if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
			p2p.isWifiP2pEnabled = true;
		} else {
			showMessage(R.string.event_p2p_disable);
			resetData();
		}
	} else if (WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
		new Wifip2pRequestPeers(eventHelper).execute(p2p);

	} else if (WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
		WifiP2pDevice me = (WifiP2pDevice) intent
				.getParcelableExtra(EXTRA_WIFI_P2P_DEVICE);

		thisDevice.setText(getWifiP2pDeviceInfo(me));
	}
}
 
Example 2
Source File: WifiDisplayController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    if (action.equals(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION)) {
        // This broadcast is sticky so we'll always get the initial Wifi P2P state
        // on startup.
        boolean enabled = (intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE,
                WifiP2pManager.WIFI_P2P_STATE_DISABLED)) ==
                WifiP2pManager.WIFI_P2P_STATE_ENABLED;
        if (DEBUG) {
            Slog.d(TAG, "Received WIFI_P2P_STATE_CHANGED_ACTION: enabled="
                    + enabled);
        }

        handleStateChanged(enabled);
    } else if (action.equals(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION)) {
        if (DEBUG) {
            Slog.d(TAG, "Received WIFI_P2P_PEERS_CHANGED_ACTION.");
        }

        handlePeersChanged();
    } else if (action.equals(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) {
        NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(
                WifiP2pManager.EXTRA_NETWORK_INFO);
        if (DEBUG) {
            Slog.d(TAG, "Received WIFI_P2P_CONNECTION_CHANGED_ACTION: networkInfo="
                    + networkInfo);
        }

        handleConnectionChanged(networkInfo);
    } else if (action.equals(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION)) {
        mThisDevice = (WifiP2pDevice) intent.getParcelableExtra(
                WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        if (DEBUG) {
            Slog.d(TAG, "Received WIFI_P2P_THIS_DEVICE_CHANGED_ACTION: mThisDevice= "
                    + mThisDevice);
        }
    }
}
 
Example 3
Source File: WiFiDirectActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  int state = intent.getIntExtra(
    WifiP2pManager.EXTRA_WIFI_STATE,
    WifiP2pManager.WIFI_P2P_STATE_DISABLED);

  switch (state) {
    case (WifiP2pManager.WIFI_P2P_STATE_ENABLED):
      // TODO Enable discovery option in the UI.
      break;
    default:
      // TODO Disable discovery option in the UI.
  }
}
 
Example 4
Source File: WifiDirectHandler.java    From WiFi-Buddy with MIT License 5 votes vote down vote up
/**
 * Indicates whether Wi-Fi P2P is enabled
 * Determine if Wi-Fi P2P mode is enabled or not, alert the Activity
 * Available extras: EXTRA_WIFI_STATE
 * Sticky Intent
 * @param intent
 */
private void handleP2pStateChanged(Intent intent) {
    Log.i(TAG, "Wi-Fi P2P State Changed:");
    int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
    if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
        // Wi-Fi Direct is enabled
        isWifiP2pEnabled = true;
        Log.i(TAG, "- Wi-Fi Direct is enabled");
    } else {
        // Wi-Fi Direct is not enabled
        isWifiP2pEnabled = false;
        Log.i(TAG, "- Wi-Fi Direct is not enabled");
    }
}
 
Example 5
Source File: SalutBroadcastReceiver.java    From Salut with MIT License 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {

        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);

        if (state != WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            Log.v(TAG, " WiFi P2P is no longer enabled.");
        }
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

        if (manager == null) {
            return;
        }

        NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

        if (networkInfo.isConnected() && networkInfo.getTypeName().equals("WIFI_P2P")) {
            salutInstance.isConnectedToAnotherDevice = true;
            manager.requestConnectionInfo(channel, salutInstance);

        } else {

            salutInstance.isConnectedToAnotherDevice = false;

            Log.v(TAG, "Not connected to another device.");
            if (salutInstance.thisDevice.isRegistered) {
                if (salutInstance.unexpectedDisconnect != null) {
                    salutInstance.unregisterClient(salutInstance.unexpectedDisconnect, null, false);
                }
            }

        }

    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {

        WifiP2pDevice device = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);

        if (salutInstance.thisDevice.deviceName == null) {
            salutInstance.thisDevice.deviceName = device.deviceName;
            salutInstance.thisDevice.macAddress = device.deviceAddress;
        }
    }

}
 
Example 6
Source File: WiFiDirectBroadcastReceiver.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "in on receive ");
    String action = intent.getAction();

    Logger.log(LogTypes.TYPE_WIFI_DIRECT, "onReceive of WifiDirectBroadCastReceiver with action: " + action);

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {

        // UI update to indicate wifi p2p status.
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            Log.d(TAG, "BR enabled");
            // Wifi Direct mode is enabled
            activity.setIsWifiP2pEnabled(true);
        } else {
            Log.d(TAG, "BR not enabled");
            activity.setIsWifiP2pEnabled(false);
            activity.resetData();

        }
        Log.d(TAG, "P2P state changed - " + state);
    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {

        // 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) {

            activity.onPeersChanged();

        }
        Log.d(TAG, "P2P peers changed2");
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

        if (manager == null) {
            return;
        }

        NetworkInfo networkInfo = intent
                .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

        activity.onP2PConnectionChanged(networkInfo.isConnected());

    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        Log.d(TAG, "in last else with device: " + intent.getParcelableExtra(
                WifiP2pManager.EXTRA_WIFI_P2P_DEVICE).toString());


        activity.onThisDeviceChanged(intent);


    }
}