예제 #1
0
 /// <summary>
 /// <see cref="WifiP2pActivity.OnWifiP2pStateChanged(EWifiState)"/>
 /// </summary>
 override public void OnWifiP2pStateChanged(EWifiState newState)
 {
     // TODO Wifi P2P enabled / disabled.
 }
 /// <summary>
 /// <see cref="IWifiP2pCallbacksHandler.OnWifiP2pStateChanged(EWifiState)"/>
 /// </summary>
 abstract public void OnWifiP2pStateChanged(EWifiState newState);
 /// <summary>
 /// <see cref="IWifiP2pCallbacksHandler.OnWifiP2pStateChanged(EWifiState)"/>
 /// </summary>
 virtual public void OnWifiP2pStateChanged(EWifiState newState)
 {
 }
 /// <summary>
 /// <see cref="IWifiP2pCallbacksHandler.OnWifiP2pStateChanged(EWifiState)"/>
 /// </summary>
 override public void OnWifiP2pStateChanged(EWifiState newState)
 {
     // Do nothing
 }
        /// <summary>
        /// <see cref="BroadcastReceiver.OnReceive(Context, Intent)"/>
        /// </summary>
        override public void OnReceive(Context context, Intent intent)
        {
            // Filter Messages intents
            if (intent is WifiP2pMessageIntent messageIntent)
            {
                // Load extra data from the intent.
                messageIntent.Load();
                switch (messageIntent.Action)
                {
                case WifiP2pMessageIntent.ActionMessageReceivedProgress:
                    if (messageIntent.IsCompleted)
                    {
                        m_CallbackHandler.OnMessageReceived(messageIntent.Message);
                    }
                    else
                    {
                        m_CallbackHandler.OnMessageReceivedProgressChanged(messageIntent.Message.MessageType, messageIntent.Progress);
                    }
                    break;

                case WifiP2pMessageIntent.ActionMessageSentProgress:
                    if (messageIntent.IsCompleted)
                    {
                        m_CallbackHandler.OnMessageSent(messageIntent.Message);
                    }
                    else
                    {
                        m_CallbackHandler.OnMessageSendingProgressChanged(messageIntent.Message, messageIntent.Progress);
                    }
                    break;
                }
            }
            else
            {
                switch (intent.Action)
                {
                case WifiP2pConnectionChangedAction:
                    NetworkInfo  networkInfo = (NetworkInfo)intent.GetParcelableExtra(ExtraNetworkInfo);
                    WifiP2pInfo  p2pInfo     = (WifiP2pInfo)intent.GetParcelableExtra(ExtraWifiP2pInfo);
                    WifiP2pGroup groupInfo   = (WifiP2pGroup)intent.GetParcelableExtra(ExtraWifiP2pGroup);
                    m_CallbackHandler.OnWifiP2pConnectionChanged(networkInfo, p2pInfo, groupInfo);
                    break;

                case WifiP2pPeersChangedAction:
                    WifiP2pDeviceList peers = (WifiP2pDeviceList)intent.GetParcelableExtra(ExtraP2pDeviceList);
                    m_CallbackHandler.OnPeersAvailable(peers);
                    break;

                case WifiP2pStateChangedAction:
                    EWifiState wifiState = (EWifiState)intent.GetIntExtra(ExtraWifiState, 0);
                    m_CallbackHandler.OnWifiP2pStateChanged(wifiState);
                    break;

                case WifiP2pThisDeviceChangedAction:
                    WifiP2pDevice deviceDetails = (WifiP2pDevice)intent.GetParcelableExtra(ExtraWifiP2pDevice);
                    m_CallbackHandler.OnThisDeviceChanged(deviceDetails);
                    break;

                default:
                    throw new NotSupportedException($"The action {intent.Action} is not handled by this receiver.");
                }
            }
        }