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

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

Introduction

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

Prototype

String EXTRA_WIFI_P2P_DEVICE

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

Click Source Link

Document

The lookup key for a android.net.wifi.p2p.WifiP2pDevice object Retrieve with android.content.Intent#getParcelableExtra(String) .

Usage

From source file:pl.edu.wat.wel.androidterminal.WiFiDirectBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(WiFiP2PFragment.TAG, action);//from  www. j  a v  a 2s .c o m
    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
            Log.d(WiFiP2PFragment.TAG, "Connected to p2p network. Requesting network details");
            manager.requestConnectionInfo(channel, (ConnectionInfoListener) activity);
        } else {
            // It's a disconnect
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {

        WifiP2pDevice device = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(WiFiP2PFragment.TAG, "Device status -" + device.status);

    }
}

From source file:org.commcare.android.framework.WiFiDirectManagementFragment.java

public void onThisDeviceChanged(Intent intent) {

    setStatusText("This device's connection status changed...");

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

    int status = mDevice.status;

    if (status == WifiP2pDevice.AVAILABLE && isHost) {
        Logger.log(CommCareWiFiDirectActivity.TAG, "Relaunching Wi-fi direct group as host");
        setStatusText("Host relaunching group...");
        mManager.createGroup(mChannel, this);
    }//  w w  w  .  j a  v a 2s  .c om

    mStatus = status;

    mActivity.updateDeviceStatus(mDevice);

}

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 .j  av a 2  s.  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));*/
    }
}