code: def connect(cls, ssid, key=None, **kwargs):
          
          app = AndroidApplication.instance()
          f = app.create_future()
  
          config = WifiConfiguration()
          config.SSID = '"{}"'.format(ssid)
          if key is not None:
              config.preSharedKey = '"{}"'.format(key)
  
          #: Set any other parameters
          for k, v in kwargs.items():
              setattr(config, k, v)
  
          def on_permission_result(result):
              if not result:
                  f.set_result(None)
                  return
  
              def on_ready(mgr):
  
                  def on_disconnect(result):
                      if not result:
                          f.set_result(None)
                          return  #: Done
                      mgr.setWifiEnabled(True).then(on_wifi_enabled)
  
                  def on_wifi_enabled(enabled):
                      if not enabled:
                          #: Access denied or failed to enable
                          f.set_result(None)
                          return
                      mgr.addNetwork(config).then(on_network_added)
  
                  def on_network_added(net_id):
                      if net_id == -1:
                          f.set_result(False)
                          print("Warning: Invalid network "
                                "configuration id {}".format(net_id))
                          return
                      mgr.enableNetwork(net_id, True).then(on_network_enabled)
  
                  def on_network_enabled(result):
                      if not result:
                          #: TODO: Should probably say
                          #: which state it failed at...
                          f.set_result(None)
                          return
  
                      mgr.reconnect().then(f.set_result)
  
                  #: Enable if needed
                  mgr.disconnect_().then(on_disconnect)
  
              #: Get the service
              WifiManager.get().then(on_ready)
  
          #: Request permissions
          WifiManager.request_permission(
              WifiManager.PERMISSIONS_REQUIRED).then(on_permission_result)
          return f
docs: Connect to the given ssid using the key (if given).
          
          Returns
          --------
              result: future
                  A future that resolves with the result of the connect