I looked for it during my project. My requirements were to uniquely identify devices in an adhoc P2p network formed using Wi-Fi Direct. Each device should identify its friendly device the next time it approaches. I need my own WiFi (Direct) MAC and my friends to create a key to create this zone for friends.
My research:. The design is designed in such a way that there is a unique universal identifier and a local identifier. Reason: A universal identifier can only be used to connect to infrastructure mode networks. The local identifier can be used for ad-hoc networks (device for device). In this ad-hoc mode, it is possible that one device can belong to several ad-hoc groups at the same time.
- Therefore, to support these parallel operations, support for P2p devices. Several MAC objects, possibly on different channels.
- For each session, the persistent group MAY use a different channel and MAC device for each session.
- P2P devices use their global MAC address as a device identifier during discovery and negotiation and a temporary local MAC address for all frames within the group. Clear from here
However, there is no direct way to get your own WiFi P2p MAC address. Problem 53437: Android .
In this discussion of the problem, a project member from Google suggested that it was possible and simple that it was not documented
Solution: Use the intent filter WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
and the optional intent WifiP2pManager.EXTRA_WIFI_P2P_DEVICE
This is how I used it in my project:
@Override public void onReceive(Context context, Intent intent) { .... .... String action = intent.getAction(); if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION .equals(action)) { WifiP2pDevice device = (WifiP2pDevice) intent .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); String myMac = device.deviceAddress; Log.d(TAG, "Device WiFi P2p MAC Address: " + myMac); sharedPref = context.getSharedPreferences(context.getString(R.string.sp_file_name), Context.MODE_PRIVATE); String MY_MAC_ADDRESS = sharedPref.getString(context.getString(R.string.sp_field_my_mac), null); if (MY_MAC_ADDRESS == null || MY_MAC_ADDRESS != myMac) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(context.getString(R.string.sp_field_my_mac), myMac); editor.commit(); }
Hope this helps someone!
source share