Android Question Proper way to end a WiFi-Direct Connection

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I cannot seem to end and then start again a WiFi-Direct Connection.

Can someone explain to me what has to be done and what order?

B4X:
    Private manager                             As WifiManager
    Private server                             As ServerSocket
    Private client                             As Socket
    Private astream                         As AsyncStreams

I've tried these in different orders
B4X:
                astream.Close                
                client.Close
                server.Close
                manager.CancelConnections

I would think there must be a nice clean way to shut down and then restart the connection process again.

It seems after being connected my only way to redo the connection is to turn off WiFi and then turn it back on.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Well here is my conversion to B4XPages.

Made the whole WiFiDirect as separate page so it is easy to plug in.

Must click on Discover on both devices.
List of devices available will be shown.
Click on one you want to connect to

Still haven't figured how to easy shut everything down, if and when I do will repost.
But have added a button "Try Reset WiFi" that opens the Wifi settings dialog so you can turn off and on again and that seems to fix any problems

Enjoy

BobVal

PS: Choose landscape mode because that's how devices sit above my keyboard.
 

Attachments

  • Project.zip
    39.5 KB · Views: 244
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Hi!, I wanted to test your example, but I get an error
1674832799944.png

The purpose of these lines is not clear, usually in the examples, B4X, I did not see this.
1674832972302.png
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Did the WifiDirect library fix the problem?

As for the lines you highlited in the second picture - not sure what you are asking, the custom build actions are in every B4X program I create by default
 
Upvote 0
Top