Android Tutorial Android Wifi-Direct Tutorial

Paulsche

Well-Known Member
Licensed User
Longtime User
The connection works, how can I send a file now?
 

LucaMs

Expert
Licensed User
Longtime User
I apologize in advance for the question asked without reading everything.

it is possible that the app accept connections automatically, without user intervention?

I was thinking of an app in which the user activates a function of listening and the app analyzes the first data received and then decides whether to continue the connection.
 

scrat

Active Member
Licensed User
Longtime User
The library works well, thanks.

Just 2 problems:
How to disconnect from a group to connect to another.
I have to manually delete the connection in the wifi parameters to be able to reconnect

When I use manager.GetCurrentStatus I have this error
B4X:
java.lang.Exception: Sub manager_connectionchanged signature does not match expected signature.
and the subis
B4X:
Sub Manager_ConnectionChanged(Connected As Boolean, GroupOwnerIp As String)


thank you
 

scrat

Active Member
Licensed User
Longtime User
About the first problem, what happens when you call DiscoverPeers again?
the devices list is refreshed noting more.

the scenario
Three devices "A"," B"," C" in the same room
After a Discover "A" see "B" and "C", "B" see "A" and "C" etc ...
"A" connects to "B" with "B" Mac adress and exchange something.
"A" wants to disconnect from "B" and connect to "C" in a new "AC" group (without B inside)
Howto disconnect and remove "AB" group ?

In the api doc i see removeGroup and createGroup methods.
these methods may be the solution?
 

scrat

Active Member
Licensed User
Longtime User
Nothing.
Device A is always connected to B

before connection with C I try to disconnect

B4X:
Public Sub Disconnect
If client.IsInitialized Then client.Close
If server.IsInitialized Then server.Close
manager.CancelConnections
End Sub

Other problem
I close and kill the app on A and B
I restart app on A et B
I try to connect to C from A and the connection is alway on A and B
 

scrat

Active Member
Licensed User
Longtime User
Yes it works afer close server, client and redim wifimanager

B4X:
Public Sub Init
    If server.IsInitialized Then server.Close
    If client.IsInitialized Then client.Close
    Dim server As ServerSocket
    Dim client As Socket
    Dim manager As WifiManager
    server.Initialize(port, "server")
    manager.Initialize("manager")
    UpdateUI
End Sub

Yes it works.
But I must wait a long time before reconnecting (~5")
If I connect just after WifiManager_ConnectionChanged nothing works and I must cut wifi or reboot.
 

antonomase

Active Member
Licensed User
Longtime User
Hi,

I have 2 phones A and B and 2 tablets X and Y, all in the same room. The phones are used as remote controls of the tablets.
I want to connect the phone A on the tablet X and the phone B on tablet Y.

In my App on the phones, I want to display the Mac adress of the discovered devices.

Question 1: In the device list set by the method Manager_PeersDiscovered (Success As Boolean, Devices As List), how to get the deviceAddress of each discovered device ? What type of object is in the ArrayList named Devices ?
Found : Devices is an Array of WifiDevices (need to read file WifiDirect.xml to find it)
But : Why having an object which seems to have a lot of properties and just two getters (name et MacAdddress) ?

Question 2 : On each tablet, how to display the mac Address of the wifi so the user can see which phone must be connected to the tablet ?
Found : using Library ABWifi
But : on each the device, the mac address with ABWifi begins witch 5C and with Wifi direct begins with 5E (the other digits are OK). Why ?

Thanks
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why having an object which seems to have a lot of properties and just two getters
Not sure that I understand the question. Which property do you need to access?

About the mac address. I don't know how ABWifi is implemented however the values in the PeersDiscovered event come directly from the underlying layer.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…