当前位置: 首页>>代码示例>>Java>>正文


Java WifiP2pManager.WIFI_P2P_STATE_ENABLED属性代码示例

本文整理汇总了Java中android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED属性的典型用法代码示例。如果您正苦于以下问题:Java WifiP2pManager.WIFI_P2P_STATE_ENABLED属性的具体用法?Java WifiP2pManager.WIFI_P2P_STATE_ENABLED怎么用?Java WifiP2pManager.WIFI_P2P_STATE_ENABLED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.net.wifi.p2p.WifiP2pManager的用法示例。


在下文中一共展示了WifiP2pManager.WIFI_P2P_STATE_ENABLED属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onWifiP2pStateChanged

/**
 * Receives events indicating whether Wifi Direct is enabled or disabled.
 */
private void onWifiP2pStateChanged(Context context, Intent intent) {
  // Since int is a simple type, we have to provide a default value
  // in case the requested key isn't contained as an extra.
  int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, 
                                 DEFAULT_EXTRA_INT);
  if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
    Log.d(TAG, "Wifi Direct enabled");
    // Wifi Direct mode is enabled
    // TODO(lerner): Do something since it's enabled?
  } else if (state == WifiP2pManager.WIFI_P2P_STATE_DISABLED) {
    Log.d(TAG, "Wifi Direct disabled");
    // Wifi Direct mode is disabled
    // TODO(lerner): Do something since it's disabled?
  } else if (state == DEFAULT_EXTRA_INT) {
    Log.e(TAG, "Wifi P2P state changed event handled, but the intent " +
               "doesn't include an int to tell whether it's enabled or " +
               "disabled!");
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:22,代码来源:WifiDirectSpeaker.java

示例2: onReceive

@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);
        } else {
            //activity.setIsWifiP2pEnabled(false);
        }
        Log.d(TAG, "P2P state changed");
    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
        Log.d(TAG, "P2P peers changed");
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        Log.d(getClass().getName(), "P2P connection changed");

        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
            manager.requestConnectionInfo(channel, connectionInfoListener);
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        // NOTE(JS): Getting the hardware id of this device and passing it to the activity so it can be shown
        WifiP2pDevice thisDevice = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);

        transfer.setConnectionSpecificInfo(thisDevice.deviceAddress);
        Log.d(TAG, "This device changed");
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:34,代码来源:WiFiDirectConnection.java

示例3: onReceive

@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
            listener.setIsWifiP2pEnabled(true);
        } else {
            listener.setIsWifiP2pEnabled(false);

        }
    } 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)
            manager.requestPeers(channel, (PeerListListener) listener);
    } 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
            manager.requestConnectionInfo(channel, (ConnectionInfoListener) listener);
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        listener.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
                WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
    }
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:37,代码来源:WiFiDirectBroadcastReceiver.java

示例4: onWifiP2pStateChanged

/**
 * Receives events indicating whether Wifi Direct is enabled or disabled.
 */
private void onWifiP2pStateChanged(Context context, Intent intent) {
  // Since int is a simple type, we have to provide a default value
  // in case the requested key isn't contained as an extra.
  int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, 
                                 DEFAULT_EXTRA_INT);
  if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
    log.debug( "Wifi Direct enabled");
      Log.d("peerDebug", "Wifi Direct enabled");
    // Wifi Direct mode is enabled
      dismissNoWifiNotification();
  } else if (state == WifiP2pManager.WIFI_P2P_STATE_DISABLED) {
      showNoWifiNotification(context);
    log.debug("Wifi Direct disabled");
      Log.d("peerDebug", "Wifi Direct disabled");
    // Wifi Direct mode is disabled
  } else if (state == DEFAULT_EXTRA_INT) {
    log.error( "Wifi P2P state changed event handled, but the intent " +
               "doesn't include an int to tell whether it's enabled or " +
               "disabled!");
      Log.d("peerDebug",  "Wifi P2P state changed event handled, but the intent " +
              "doesn't include an int to tell whether it's enabled or " +
              "disabled!");
  } else {
      log.error("Wifi P2P state changed to an unknown state:"+state);
      Log.d("peerDebug","Wifi P2P state changed to an unknown state:"+state);
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:30,代码来源:WifiDirectSpeaker.java

示例5: handleP2pStateChanged

/**
 * 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");
    }
}
 
开发者ID:Crash-Test-Buddies,项目名称:WiFi-Buddy,代码行数:20,代码来源:WifiDirectHandler.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        // Check to see if Wi-Fi is enabled and notify appropriate activity
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            // Wifi P2P is enabled
            Log.v("ServerService","on receive. wifi p2p is enabled");
        } else {
            // Wi-Fi P2P is not enabled
            Log.v("ServerService","on receive. wifi p2p is disabled");
            //serverOutcomeCommunication.createLobby(null);
        }
   /* } 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 (networkingService.mManager != null && !networkingService.connected) {
            networkingService.mManager.requestPeers(networkingService.mChannel, networkingService.peerListListener);
        }
        Log.v("Test", "P2P peers changed");*/
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        if (networkingService.getmManager() == null) {
            return;
        }
        Log.d("Client","on receive. connection changed action, connected: " + networkingService.isConnected());
        if (networkInfo.isConnected() && !networkingService.isConnected()) {
            networkingService.setConnected(true);
            // We are connected with the other device, request connection
            // info to find group owner IP
            ConnectionInfoListener connectionInfoListener = new ConnectionInfoListener((Client) networkingService);
            networkingService.getmManager().requestConnectionInfo(networkingService.getmChannel(), connectionInfoListener);
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        // Respond to this device's wifi state changing
    }

}
 
开发者ID:woodplantation,项目名称:werewolf,代码行数:40,代码来源:WifiP2pBroadcastReceiver.java

示例7: onReceive

@Override
 public void onReceive(Context context, Intent intent) {
     super.onReceive(context, intent);

     if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
         // Check to see if Wi-Fi is enabled and notify appropriate activity
         int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
         if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
             // Wifi P2P is enabled
             Log.v("ServerService","on receive. wifi p2p is enabled");
         } else {
             // Wi-Fi P2P is not enabled
             Log.v("ServerService","on receive. wifi p2p is disabled");
             ((ServerOutcomeBroadcastSender) networkingService.getOutcomeBroadcastSender()).createLobby(null, 0);
         }
/*     } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
         // Call WifiP2pManager.requestPeers() to get a list of current peers
         if (networkingService.mManager != null && networkingService.connected) {
             networkingService.mManager.requestPeers(networkingService.mChannel, networkingService.peerListListener);
         }*/
     } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
         // Respond to new connection or disconnections
         if (networkInfo != null && networkInfo.isConnected() && wifiP2pInfo != null && wifiP2pInfo.groupFormed && wifiP2pInfo.isGroupOwner && !networkingService.isConnected()) {
             if (((Server) networkingService).getMac() == null) {
                 ((ServerOutcomeBroadcastSender) networkingService.getOutcomeBroadcastSender()).createLobby(null, 0);
                 networkingService.stopSelf();
                 return;
             }
             networkingService.setConnected(true);
             ((Server) networkingService).initServerSocket();
         }
     } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
         if (wifiP2pDevice != null && ((Server) networkingService).getMac() == null) {
             ((Server) networkingService).setMac(wifiP2pDevice.deviceAddress);
         }
     }

 }
 
开发者ID:woodplantation,项目名称:werewolf,代码行数:38,代码来源:WifiP2pBroadcastReceiver.java

示例8: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { // Called if WIFI On/Off changed.

        // 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
            wfd.setIsWifiP2pEnabled(true);
        } else {
            wfd.setIsWifiP2pEnabled(false);
            wfd.resetData();
        }

        Log.d(TAG, "onReceive : P2P state changed - " + state);

    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { // Called if this device found something other device.

        // request available peers from the wifi p2p manager. This is an
        // asynchronous call and the calling wfd is notified with a
        // callback on PeerListListener.onPeersAvailable()

        if (manager == null) {
            return;
        }

        manager.requestPeers(channel, connector);

        Log.d(TAG, "onReceive : P2P peers changed");

    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { // Called if this device connect/disconnect opponent device.

        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

            manager.requestConnectionInfo(channel, communicator);

        } else {
            // It's a disconnect
            //wfd.resetData();
        }

        Log.d(TAG,"BroadCaster : P2P Connection Changed");

    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { // Called if changed this device status

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

        Log.d(TAG,"onReceive : This Device Status is Changed");
    }
}
 
开发者ID:jphacks,项目名称:TK_1701,代码行数:63,代码来源:WiFiDirectBroadcastReceiver.java

示例9: onReceive

@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        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-p2p on
                // Wifi-p2p mode is enabled

            } else { //wifi-p2p off

            }
            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) {
                manager.requestPeers(channel, this);
            }
            Log.d(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
                isConnected = true;
                manager.requestConnectionInfo(channel, this);
                Log.d(TAG, "device Connected!!--->requestConnectionInfo()");
            } else {
                // It's a disconnect
                isConnected = false;
                currentConnectMAC = null;
                Log.d(TAG, "device disconnected!!)");
                release();
                handler.sendEmptyMessage(WIFIP2P_DEVICE_DISCONNECTED); //设置断开连接
            }
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
//            DeviceListFragment fragment = (DeviceListFragment) activity.getFragmentManager()
//                    .findFragmentById(R.id.frag_list);
//            fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
//                    WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
        } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
            updateWifiMac();
        }
    }
 
开发者ID:lucky-code,项目名称:Practice,代码行数:56,代码来源:WifiP2pHelper.java

示例10: onReceive

@Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            // Determine if Wifi P2P mode is enabled or not, alert
            // the Activity.
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                activity.setIsWifiP2pEnabled(true);
                Log.e("WiFiP2PBroadcast","enable");
            } else {
                activity.setIsWifiP2pEnabled(false);
                Log.e("WiFiP2PBroadcast","unable");
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {

            // The peer list has changed!  We should probably do something about
            // that.
//            Log.e("WiFiP2PBroadcast","WIFI_P2P_PEERS_CHANGED_ACTION");
            if (mManager != null) {
                mManager.requestPeers(mChannel, peerListListener);
            }

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

            // Connection state changed!  We should probably do something about
            // that.
            Log.e("WiFiP2PBroadcast","WIFI_P2P_CONNECTION_CHANGED_ACTION");
            if (mManager == 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

                mManager.requestConnectionInfo(mChannel, connectionListener);
            }

        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
            Log.e("WiFiP2PBroadcast",((WifiP2pDevice) intent.getParcelableExtra(
                    WifiP2pManager.EXTRA_WIFI_P2P_DEVICE)).toString());
//            DeviceListFragment fragment = (DeviceListFragment) activity.getFragmentManager()
//                    .findFragmentById(R.id.frag_list);
//            fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
//                    WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));

            activity.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
                    WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));

        }
    }
 
开发者ID:niyueming,项目名称:WiFiP2PDemo,代码行数:56,代码来源:WiFiP2PBroadcastReceiver.java

示例11: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    // Get the action identifier
    String action = intent.getAction();

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        // The Wifi state has changed.
        // Check if the WiFi is enabled or not.
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            // Wifi enabled!, start the peers discovery.
            activity.discoverPeers();

        } else {
            // Error: Wifi Direct disabled, enable it.
            Toast.makeText(activity.getApplicationContext(), R.string.aqrdt_operation_enabling_wifi, Toast.LENGTH_SHORT).show();
            WifiManager wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
            wifi.setWifiEnabled(true);
        }

    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
        // Wifi P2P peers changed.
        // Maybe Discovery of peers has finished and the client could be able to scan for QR codes now.
        activity.peersChanged();

    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        // Wifi P2P connection has changed.
        // Check if the device is connected or not.
        if (manager == null) {
            return;
        }

        NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
        if (networkInfo.isConnected()) {
            // Connected with the other device, request more info.
            manager.requestConnectionInfo(channel, activity);

        } else {
            // Disconnected
            if (activity.isConnected && !activity.isFinishingTransmission){
                // Error: the other peer has disconnected during transmission.
                // It's not legal because I'm not in "finishing" state.
                // Finish the transmission with error.
                activity.finishTransmissionWithError();
            }
        }

    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        // This device's wifi p2p connection state changed.
        // Update the info about this device.
        WifiP2pDevice thisDevice = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        activity.updateThisDevice(thisDevice.deviceAddress);
    }
}
 
开发者ID:prgpascal,项目名称:android-qr-data-transfer,代码行数:54,代码来源:WiFiDirectBroadcastReceiver.java


注:本文中的android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。