Example usage for android.net.wifi.p2p WifiP2pManager WIFI_P2P_STATE_ENABLED

List of usage examples for android.net.wifi.p2p WifiP2pManager WIFI_P2P_STATE_ENABLED

Introduction

In this page you can find the example usage for android.net.wifi.p2p WifiP2pManager WIFI_P2P_STATE_ENABLED.

Prototype

int WIFI_P2P_STATE_ENABLED

To view the source code for android.net.wifi.p2p WifiP2pManager WIFI_P2P_STATE_ENABLED.

Click Source Link

Document

Wi-Fi p2p is enabled.

Usage

From source file:com.example.android.wifidirect.WiFiDirectBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    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) {
            // Wifi Direct mode is enabled
            activity.setIsWifiP2pEnabled(true); //Wi-Fi direct??
        } else {/* w w w  .ja  va 2s  . co  m*/
            activity.setIsWifiP2pEnabled(false);
            activity.resetData();

        }
        Log.d(WiFiDirectActivity.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()
        //Wi-Fi P2P??PeerListListener.onPeersAvailable()?
        if (manager != null) {
            FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity
                    .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0");
            DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager()
                    .findFragmentById(R.id.frag_list);
            manager.requestPeers(channel, (PeerListListener) fragment);
        }
        Log.d(WiFiDirectActivity.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
            // info to find group owner IP
            FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity
                    .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0");
            DeviceDetailFragment fragment = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager()
                    .findFragmentById(R.id.frag_detail);
            manager.requestConnectionInfo(channel, fragment); //??onConnectionInfoAvailable
        } else {
            // It's a disconnect       
            activity.resetData();
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { //????
        //DeviceListFragment fragment = (DeviceListFragment) activity.getSupportFragmentManager().findFragmentByTag("devicelistfragment");
        FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity.getSupportFragmentManager()
                .findFragmentByTag("android:switcher:" + R.id.pager + ":0");
        DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager()
                .findFragmentById(R.id.frag_list);
        fragment.updateThisDevice(
                (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
        //activity.getSupportFragmentManager().beginTransaction().add(R.id.list_fragment, fragment).commit();

        //DeviceDetailFragment fragment2 = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager().findFragmentById(R.id.frag_detail);
        //fragment2.getrootView().setVisibility(View.VISIBLE);

        /*Log.d(WiFiDirectActivity.TAG,"Fragment2:"+fragment2);
        Log.d(WiFiDirectActivity.TAG,"Fragment2.getView():"+fragment2.getView());
        Log.d(WiFiDirectActivity.TAG,"Fragment2.getrootView():"+fragment2.getrootView());
        Log.d(WiFiDirectActivity.TAG, "Fragment:"+fileTransmitfragment);
        Log.d(WiFiDirectActivity.TAG, "device:"+(WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));*/
    }
}