Using a WiFi without Internet Connection

后端 未结 3 478
日久生厌
日久生厌 2020-12-17 03:51

In my app I am connecting to a device that has it\'s own WiFi network. In android 6 and above the system asks me after a few seconds if I want to connect to this network eve

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 04:19

    For those still attempting to figure this out, based on the

    wifiNetwork.bindSocket(socket)
    

    provided by @MayconPrado

    Yes, that socket variable was declared ahead of time. That answer assumes you are sending UDP or TCP packets over the network.

    The partial but more complete code would look something along the lines of

    val socket = DatagramSocket(somePortNumber)
    wifiNetwork.bindSocket(socket)
    val udpPacket = DatagramPacket(/** args specific to use case **/)
    socket.send(udpPacket)
    

    Would have commented this, but I have never posted to SO, so I have 1 rep ATM.

提交回复
热议问题