Android Question WiFi Direct: How to get the connecting device name?

toby

Active Member
Licensed User
If DeviceA is the group owner and is expecting connection from both DeviceB and DeviceC, how can DeviceA find out which device, B or C, is connected when the event Manager_ConnectionChanged () is raised?

I tried something similar to getting own device name, but the intent wasn't triggered. I think the following filter isn't correct; could someone show me how to fix it, please?
manifest entry:
AddReceiverText(WiFiDirectGetConnectingDeviceNameService, <intent-filter>
    <action android:name="android.net.wifi.p2p.CONNECTION_CHANGED_ACTION" /> 
</intent-filter>)

TIA
 
Last edited:

toby

Active Member
Licensed User
Below is an answer (although no one confirmed that it works) to a similar question at Stackoverflow:

When you receive the WIFI_P2P_CONNECTION_CHANGED_ACTION broadcast, if you are on API level 18 or higher, there is an extra in the intent, called EXTRA_WIFI_P2P_GROUP.

EXTRA_WIFI_P2P_GROUP

This returns a WifiP2pGroup on which you can call getClientList(). This gives you a collection of WifiP2pDevices. Once you have a WifiP2pDevice you can just get the field "deviceName".
 
Upvote 0

toby

Active Member
Licensed User
Sorry, it didn't work; the intent wasn't triggered when an incoming connection was made. Test project is attached, so that others could check if I did anything wrong.
 

Attachments

  • wifiDirectConnectingDeviceName.zip
    10 KB · Views: 83
Upvote 0

toby

Active Member
Licensed User
Sorry, I didn't know failed to see that there is such an event. The device name, zenfone3, is shown.


highlighted line shows the client device name:
(Intent) Intent { act=android.net.wifi.p2p.CONNECTION_STATE_CHANGE flg=0x24000010 (has extras) }
Bundle[{networkInfo=[type: WIFI_P2P[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false], wifiP2pInfo=groupFormed: true isGroupOwner: true groupOwnerAddress: /192.168.49.1, p2pGroupInfo=network: DIRECT-rg-pixel4a
isGO: true
GO: Device:
deviceAddress: 02:00:00:00:00:00
primary type: null
secondary type: null
wps: 0
grpcapab: 0
devcapab: 0
status: 4
wfdInfo: null
Client: Device: zenfone3
deviceAddress: 62:45:cb:28:51:bd
primary type: 10-0050F204-5
secondary type: null
wps: 392
grpcapab: 0
devcapab: 37
status: 0
wfdInfo: WFD enabled: trueWFD DeviceInfo: 16
WFD CtrlPort: 7236
WFD MaxThroughput: 50
interface: p2p-p2p0-1
networkId: 0
frequency: 5180}]
peers: true
server_NewConnection true
AsyncStreams started
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sorry, I didn't know that there is such an event
Carefully reading the answers helps a lot here. ;-)
Please try the attached, untested, update (1.06).

It adds an event named IntentReceived (Intent As Intent).

Handle this event and post the output of
 
Last edited:
Upvote 0
Top