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

The following examples show how to use android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_CHANGED_ACTION . 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: WifiP2pInfoReceiver.java    From android-p2p with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    boolean startService = true;
    Intent serviceIntent = new Intent(context, P2pChatService.class);
    switch (intent.getAction()) {
        case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
            serviceIntent.setAction("STATE_CHANGED");
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            serviceIntent.putExtra("P2P_ENABLED", (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED));
            break;
        case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION:
            Log.d("P2P", "Peers changed");
            serviceIntent.setAction("PEERS_CHANGED");
            break;
        case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION:
            Log.d("P2P", "Connection changed");
            serviceIntent.setAction("CONNECTION_CHANGED");
            break;
        default:
            startService = false;
            break;
    }
    if (startService) {
        context.startService(serviceIntent);
    }
}
 
Example 2
Source File: WiFiDirectBroadcastReceiver.java    From Wifi-Connect with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    switch (action) {
        case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            wifiP2PService.handleOnWifiStateChanged(state);
            break;

        case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_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()
            wifiP2PService.handleOnPeersChangedResponse();
            break;


        case WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION:
            // Broadcast when a device's details have changed,
            // such as the device's name
            WifiP2pDevice wifiP2pDevice = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
            wifiP2PService.handleOnDeviceStatusChanged(wifiP2pDevice);
            break;


        case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION:
            NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
            if(networkInfo.isConnected()) wifiP2PService.handleOnPeerConnected();
            else wifiP2PService.handleOnPeerDisconnected();
            break;
    }
}
 
Example 3
Source File: P2pConnect.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action=intent.getAction();
    switch (action)
    {
        case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
            int state=intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE,-1);

            if(state== WifiManager.WIFI_STATE_ENABLED)
            {
                //p2p is enable
                Log.i(TAG,"WIFI_P2P is enable");
            }
            else
            {
                //p2p is not useful
                Log.i(TAG,"WIFI_P2P is not supported");
            }
            break;

        case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION:
            _p2pManager.requestPeers(_channel,_peerListener);
            break;

        case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION:
            break;

        case WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION:
            break;
    }

    if(_receiveListener!=null)
        _receiveListener.onReceive(context,intent);
}
 
Example 4
Source File: P2pReceiver.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action=intent.getAction();
    switch (action)
    {
        case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
            int state=intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE,-1);

            if(state== WifiManager.WIFI_STATE_ENABLED)
            {
                //p2p is enable
            }
            else
            {
                //p2p is not useful
            }

            break;

        case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION:
            _wifiP2pManager.requestPeers(_channel,_peerListener);
            break;

        case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION:

            break;

        case WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION:
            break;
    }
}