/// <summary> /// Default constructor. /// Specify the timeOut in milli seconds. /// </summary> /// <param name="activity">The context.</param> /// <param name="manager">The wifi P2P manager.</param> /// <param name="channel">The channel used for wifi P2P communications.</param> /// <param name="timeOutSeconds">How long the task should keep discovering peers. Use a zero or a negative value for indefinite time.</param> /// <remarks>For indefinite times, the method <see cref="WifiP2pManager.StopPeerDiscovery(WifiP2pManager.Channel, WifiP2pManager.IActionListener)"/> must be called manually.</remarks> public DiscoverAsyncTask(Activity activity, WifiP2pManager manager, WifiP2pManager.Channel channel, float timeOutSeconds) { m_Activity = activity ?? throw new ArgumentNullException(nameof(activity)); m_WifiP2pManager = manager ?? throw new ArgumentNullException(nameof(manager)); m_WifiP2pChannel = channel ?? throw new ArgumentNullException(nameof(channel)); m_TimeOutSeconds = timeOutSeconds; }
override protected void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_access_point); m_Views = new AccessPointViews(this); m_Views.DetailsLayout.Visibility = ViewStates.Gone; m_PermissionService = new PermissionService(this); m_Clients = new HashSet <WifiP2pDevice>(); m_Adapter = new WifiPeerAdapter(m_Clients); m_Views.MembersRecyclerView.SetAdapter(m_Adapter); FindViewById <ViewGroup>(Resource.Id.layout_root).LayoutTransition.EnableTransitionType(Android.Animation.LayoutTransitionType.Changing); InitializeButtons(); if (!m_PermissionService.IsPermissionGroupGranted(PermissionConstants.WifiP2pPermissionGroup)) { m_PermissionService.RequestPermissions(PermissionConstants.WifiP2pPermissionsGroupId, PermissionConstants.WifiP2pPermissionGroup); } else { WifiP2pManager.CreateGroup(WifiP2pChannel, new WifiP2pActionListener(this, EWifiP2pAction.CreateGroup, () => { Toast.MakeText(this, "Groupe créé avec succès !", ToastLength.Short).Show(); })); } }
/// <summary> /// <see cref="Activity.OnRequestPermissionsResult(int, string[], Permission[])"/> /// </summary> override public void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PermissionConstants.WifiP2pPermissionsGroupId: bool allGranted = true; for (int i = 0; i < permissions.Length; i++) { if (grantResults[i] != Permission.Granted) { allGranted = false; break; } } if (!allGranted) { Toast.MakeText(this, $"Permissions refusées pour le groupe {nameof(PermissionConstants.WifiP2pPermissionGroup)}", ToastLength.Short).Show(); } else { WifiP2pManager.CreateGroup(WifiP2pChannel, new WifiP2pActionListener(this, EWifiP2pAction.CreateGroup, () => { Toast.MakeText(this, "Groupe créé avec succès !", ToastLength.Short).Show(); })); } break; default: break; } }
public WifiDirectManager() { _WifiP2pActonListener = new Receiver(this); _DiscoverPeersListener = new WifiP2pActionListener(this); _DroidWifiP2pManager = (WifiP2pManager)Application.Context.GetSystemService(Context.WifiP2pService); _Channel = _DroidWifiP2pManager.Initialize(Application.Context, Application.Context.MainLooper, null); /* * IntentFilter startFilter = new IntentFilter(BluetoothAdapter.ActionDiscoveryStarted); * IntentFilter foundFilter = new IntentFilter(BluetoothDevice.ActionFound); * IntentFilter finshFilter = new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished); * * Application.Context.RegisterReceiver(_DiscoveryStartedReceiver, startFilter); * Application.Context.RegisterReceiver(_DevicesFoundReceiver, foundFilter); * Application.Context.RegisterReceiver(_DiscoveryFinishedReceiver, finshFilter); */ IntentFilter connectionChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pConnectionChangedAction); IntentFilter peersChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pPeersChangedAction); IntentFilter stateChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pStateChangedAction); IntentFilter thisDeviceChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pThisDeviceChangedAction); Application.Context.RegisterReceiver(_WifiP2pActonListener, stateChangedFilter); Application.Context.RegisterReceiver(_WifiP2pActonListener, connectionChangedFilter); Application.Context.RegisterReceiver(_WifiP2pActonListener, peersChangedFilter); //Application.Context.RegisterReceiver() }
/// <summary> /// ctor /// </summary> /// <param name="manager">WifiP2pManager system service</param> /// <param name="channel">Wifi p2p channel</param> /// <param name="activity">activity associated with the receiver</param> public WiFiDirectBroadcastReceiver(WifiP2pManager manager, WifiP2pManager.Channel channel, MainActivity activity) { _manager = manager; _channel = channel; _activity = activity; }
public async Task <ConnectionEstablishState> ConnectAsync() { await Task.Run(() => { WifiP2pConfig config = new WifiP2pConfig(); config.DeviceAddress = (WifiDirectDevice as WifiDirectDevice).Address; WifiP2pManager droidWifiP2pManager = _WifiDirectManager._DroidWifiP2pManager; droidWifiP2pManager.Connect(_WifiDirectManager._Channel, config, _ConnectStateListener); while (!_ConnectingSucceeded) { if (_ReconnectMark) { _ReconnectMark = false; droidWifiP2pManager.Connect(_WifiDirectManager._Channel, config, _ConnectStateListener); } } WifiP2pActionListener connectionInfoListener = new WifiP2pActionListener(_WifiDirectManager); _WifiDirectManager._DroidWifiP2pManager.RequestConnectionInfo(_WifiDirectManager._Channel, connectionInfoListener); while (_WifiDirectManager._LatestWifiP2pInfo == null) { System.Diagnostics.Debug.WriteLine("HERE2"); } WifiP2pInfo preInfo = null; while (_WifiDirectManager._LatestWifiP2pInfo.GroupOwnerAddress == null) { if (preInfo != _WifiDirectManager._LatestWifiP2pInfo) { preInfo = _WifiDirectManager._LatestWifiP2pInfo; _WifiDirectManager._DroidWifiP2pManager.RequestConnectionInfo(_WifiDirectManager._Channel, connectionInfoListener); System.Diagnostics.Debug.WriteLine("CHANGE"); } System.Diagnostics.Debug.WriteLine("HERE3"); } if (_ConnectingSucceeded) { ConnectionEstablishState = ConnectionEstablishState.Succeeded; } OnConnectionEstalblishResult?.Invoke(this, ConnectionEstablishState); }); try { System.Diagnostics.Debug.WriteLine("Connect Succeed " + _WifiDirectManager._LatestWifiP2pInfo.GroupOwnerAddress.HostAddress); } catch (Exception) { var f**k = _WifiDirectManager._LatestWifiP2pInfo; } return(ConnectionEstablishState); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction); _manager = (WifiP2pManager)GetSystemService(WifiP2pService); _channel = _manager.Initialize(this, MainLooper, null); }
/// <summary> /// <see cref="Activity.OnCreate(Bundle)"/> /// </summary> override protected void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); WifiP2pManager = (WifiP2pManager)GetSystemService(WifiP2pService); WifiP2pChannel = WifiP2pManager.Initialize(this, MainLooper, null); m_WifiP2pBroadcastReceiver = new WifiP2pBroadcastReceiver(WifiP2pManager, WifiP2pChannel, this); m_WifiP2pIntentFilter = new IntentFilter(); m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction); m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction); m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction); m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction); }
private void InitializeButtons() { m_Views.DetailsButton.Click += (e, args) => { m_Views.DetailsLayout.Visibility = m_AreDetailsShown ? ViewStates.Gone : Android.Views.ViewStates.Visible; m_Views.DetailsButton.Text = m_AreDetailsShown ? "Détails" : "Cacher les détails"; m_AreDetailsShown = !m_AreDetailsShown; }; m_Views.DisconnectButton.Click += (e, args) => { WifiP2pManager.RemoveGroup(WifiP2pChannel, new WifiP2pActionListener(this, EWifiP2pAction.EndGroup)); OnBackPressed(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.main_menu); var userData = Application.Context.GetSharedPreferences("userData", FileCreationMode.Private); var name = userData.GetString("Name", ""); var nickname = userData.GetString("Nickname", ""); wifiManager = (WifiP2pManager)Application.Context.GetSystemService(Context.WifiP2pService); var intentFilter = new IntentFilter(); intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction); intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction); intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction); intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); _manager = (WifiP2pManager)GetSystemService(Activity.WifiP2pService); _channel = _manager.Initialize(this, MainLooper, null); // Set up the intent filter for the broadcast receiver _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction); _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction); // Get our button from the layout resource, // and attach an event to it buttons["upper-left"] = FindViewById <Button>(Resource.Id.button1); buttons["upper-center"] = FindViewById <Button>(Resource.Id.button2); buttons["upper-right"] = FindViewById <Button>(Resource.Id.button3); buttons["middle-left"] = FindViewById <Button>(Resource.Id.button4); buttons["middle-center"] = FindViewById <Button>(Resource.Id.button5); buttons["middle-right"] = FindViewById <Button>(Resource.Id.button6); buttons["lower-left"] = FindViewById <Button>(Resource.Id.button7); buttons["lower-center"] = FindViewById <Button>(Resource.Id.button8); buttons["lower-right"] = FindViewById <Button>(Resource.Id.button9); messageView = FindViewById <TextView> (Resource.Id.textView1); messageView.Text = "Welcome to Android Tic-Tac-Toe!"; MatchUIToBoard(); messageView.Text = string.Format("It's {0}'s turn", game.PlayersTurn); foreach (var k in buttons.Keys) { buttons [k].Tag = k; Log.Info("BCTTT", string.Format("button[{0}].Tag = {1}", k, buttons[k].Tag)); buttons [k].Click += ButtonClick; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); mLvPeers = FindViewById <ListView>(Resource.Id.lvPeers); mLvPeers.ItemClick += OnListViewItemClick; mBtShowPeers = FindViewById <Button>(Resource.Id.btShowPeers); mBtShowPeers.Click += OnListAllPeers; mManager = (WifiP2pManager)GetSystemService(WifiP2pService); mChannel = mManager.Initialize(this, MainLooper, null); mReceiver = new WifiDirectBroadcastReceiver(mManager, mChannel, this); mIntentFilter = new IntentFilter(); mIntentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction); mIntentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction); mIntentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction); mIntentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction); mPeers = new List <WifiP2pDevice>(); }
/// <summary> /// <see cref="Activity.OnCreate(Bundle)"/> /// </summary> override protected void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_client); m_Views = new ClientViews(this); m_Views.ButtonProgressBar.Visibility = ViewStates.Gone; m_Views.GlobalProgressBar.Visibility = ViewStates.Visible; m_Views.TitleLayout.Visibility = ViewStates.Gone; m_Views.NoPeersLayout.Visibility = ViewStates.Gone; m_Views.RefreshLayout.SetOnRefreshListener(this); m_Views.RefreshButton.SetOnClickListener(new BaseOnClickListener(v => { m_Views.RefreshButton.Visibility = ViewStates.Invisible; m_Views.ButtonProgressBar.Visibility = ViewStates.Visible; StartDiscovering(); })); m_CurrentPeers = new HashSet <WifiP2pDevice>(); m_Adapter = new WifiPeerAdapter(m_CurrentPeers, false, device => { WifiP2pConfig config = new WifiP2pConfig { DeviceAddress = device.DeviceAddress }; WifiP2pManager.Connect(WifiP2pChannel, config, new WifiP2pActionListener(this, EWifiP2pAction.Connect)); }); m_Views.PeersRecyclerView.SetAdapter(m_Adapter); m_PermissionService = new PermissionService(this); StartDiscovering(); }
/// <summary> /// Request for updated information about the current group. /// </summary> /// <remarks>Only the group owner can obtain the extended info about the group. Clients can only receive the owner device info. /// Catch the results with the method <see cref="OnGroupInfoAvailable(WifiP2pGroup)"/></remarks> protected void RequestGroupInfo() { WifiP2pManager.RequestGroupInfo(WifiP2pChannel, this); }
public WifiDirectBroadcastReceiver(WifiP2pManager p2pManager, WifiP2pManager.Channel p2pChannel, MainActivity mainActivity) { this.mManager = p2pManager; this.mChannel = p2pChannel; this.mMainActivity = mainActivity; }
public P2PReceiver(WifiP2pManager manager, Channel channel) { this.manager = manager; this.channel = channel; }
/// <summary> /// Default constructor. /// </summary> /// <param name="wifiP2pManager">The <see cref="WifiP2pManager"/> instance.</param> /// <param name="channel">The used channel.</param> /// <param name="callbackHandler">The global callback handler for wifi P2P signals.</param> public WifiP2pBroadcastReceiver(WifiP2pManager wifiP2pManager, Channel channel, WifiP2pActivity callbackHandler) { m_WifiP2pManager = wifiP2pManager ?? throw new ArgumentNullException(nameof(wifiP2pManager)); m_Channel = channel ?? throw new ArgumentNullException(nameof(channel)); m_CallbackHandler = callbackHandler ?? throw new ArgumentNullException(nameof(callbackHandler)); }
/// <summary> /// Request an updated peer list explicitly. /// </summary> /// <remarks>Can return an empty list if no peers have been discovered. /// Catch the results with the method <see cref="OnPeersAvailable(WifiP2pDeviceList)"/></remarks> protected void RequestUpdatedPeerList() { WifiP2pManager.RequestPeers(WifiP2pChannel, this); }
/// <summary> /// Request for updated information about the current connection i.e. if a group has been formed, the group owner inet address and whether or not this device is the group owner. /// </summary> /// <remarks>Catch the results with the method <see cref="OnConnectionInfoAvailable(WifiP2pInfo)"/></remarks> protected void RequestConnectionInfo() { WifiP2pManager.RequestConnectionInfo(WifiP2pChannel, this); }